• No results found

Examine an Example Plug-In Factory

In document vcenter Orchestrator Developer's Guide (Page 146-149)

10 Pass the plug-in name to the plug-in.

The IPluginAdaptor interface's setPluginName() method gets the name from the vso.xml file, if necessary.

public void setPluginName(String pluginName) { }

11 Unregister an IPluginEventPublisher from the Orchestrator policy engine by calling.

The solar system example adapter unregisters the IPluginEventPublisher instance created in Step 8 and removes it from the Orchestrator policy engine by calling the unregisterEventPublisher() method.

public void unregisterEventPublisher(String type, String id, IPluginEventPublisher publisher) {

getEventGenerator().removePolicyElement(type, id, publisher); }

You have a plug-in adapter implementation that creates a plug-in factory, obtains licenses, passes the plug-in name to Orchestrator, and defines how to manage events that occur in the plugged-in technology.

What to do next

Create the plug-in factory implementation to find objects through the plug-in and define how to perform operations on them.

Examine an Example Plug-In Factory

To create a plug-in factory, you create a Java class that implements the IPluginFactory interface from the Orchestrator plug-in API.

Prerequisites

The following procedure outlines the broad steps in the process to develop a plug-in factory class. For a description of the role of the plug-in factory and the other components of a plug-in, you must read

“Components and Architecture of a Plug-In,” on page 123.

Procedure

1 Create and save a Java file for the plug-in factory implementation called

<YourApplicationName>Factory.java.

In the solar system example, the factory class is called SolarSystemFactory.java.

2 Declare a package to contain the plug-in adapter and factory implementations.

The solar system example declares the following package to contain the adapter and factory implementations:

package com.vmware.orchestrator.api.sample.solarsystem;

3 Import the Orchestrator plug-in API classes into the factory implementation with a Java import statement.

import ch.dunes.vso.sdk.api.*;

4 Import the solar system application with a Java import statement.

import com.vmware.solarsystem.*;

5 Import any other classes the adapter implementation requires.

In the solar system example, the factory implementation requires the following classes:

import java.util.*;

import org.apache.log4j.Logger;

6 Declare a public constructor that implements the IPluginFactory interface from the Orchestrator plug-in API.

The solar system example adapter declares the SolarSystemFactory constructor.

public class SolarSystemFactory implements IPluginFactory { }

7 Set up logging so that Orchestrator can track the events that occur in the plugged-in technology.

private Logger log = Logger.getLogger(this.getClass());

8 Define how Orchestrator performs operations on the objects it finds through the plug-in by calling the IPluginFactory interface's executePluginCommand() method and defining the command behavior.

The SolarSystemFactory example implementation does not support any commands, so does not implement the executePluginCommand() method.

public void executePluginCommand(String cmd) throws PluginExecutionException { }

9 Define how Orchestrator finds objects through the plug-in by their name and type by implementing the IPluginFactory interface's find() method.

The SolarSystemFactory example implementation calls on methods defined by the

SolarSystemRepository class to obtain Star, Planet, and Moon objects by their type and identifier.

public Object find(String type, String id) { log.debug("find: " + type + ", " + id);

if (type.equals("Star")) {

return SolarSystemRepository.getUniqueInstance().getStar();

}

else if (type.equals("Planet")) {

return SolarSystemRepository.getUniqueInstance().getPlanetById(id);

}

else if (type.equals("Moon")) {

return SolarSystemRepository.getUniqueInstance().getMoonById(id);

}

else if (type.equals("Galaxy")) {

return null; // No object for galaxy defined yet }

else {

throw new IndexOutOfBoundsException("Type " + type + "

+ unknown for plugin SolarSystem");

} }

10 Define query rules to find objects through the plug-in according to your own query criteria by implementing IPluginFactory interface's findAll() method.

The SolarSystemFactory example implementation returns a list of all the objects of a given type. For example, it can return a list of all objects of the Planet type.

public QueryResult findAll(String type, String query) { log.debug("findAll: " + type + ", " + query);

List list; // The list can contain any element from the plug-in if (type.equals("Star")) {

list = new Vector();

list.add(SolarSystemRepository.getUniqueInstance().getStar());

}

else if (type.equals("Planet")) {

list = SolarSystemRepository.getUniqueInstance().getAllPlanets();

}

else if (type.equals("Moon")) {

list = SolarSystemRepository.getUniqueInstance().getAllMoons();

}

else if (type.equals("Galaxy")) { list = new Vector();

} else {

throw new IndexOutOfBoundsException("Type " + type + " unknown for SolarSystem plug-in ");

}

return new QueryResult(list);

}

The SolarSystemFactory class's implementation of the findAll() method does not define a custom query, so it returns a list of all the objects of the given type in a QueryResult object.

11 Define how Orchestrator finds objects through the plug-in by their relations to other objects by implementing the IPluginFactory interface's findRelation() method.

The SolarSystemFactory example implements findRelation() to return all the planets that orbit a given star, or all the moons that orbit a given planet.

public List findRelation(String parentType, String parentId, String relationName) { log.debug("findRelation: " + parentType + ", " + parentId + ", " + relationName);

if (parentId == null) {

List<Star> list = new Vector<Star>();

list.add(SolarSystemRepository.getUniqueInstance().getStar());

return list;

}

if (parentType.equals("Star")) {

if (relationName.equals("OrbitingPlanets")) {

} else {

throw new IndexOutOfBoundsException("Unknown relation name: "

+ relationName);

} }

if (parentType.equals("Planet")) {

if (relationName.equals("OrbitingMoons")) { Planet parentPlanet =

SolarSystemRepository.getUniqueInstance().getPlanetById(parentId);

if (parentPlanet != null) {

throw new IndexOutOfBoundsException("Unknown relation name: "

+ relationName);

The SolarSystemFactory example's findRelation() method returns a list of objects that relate to the parent by the OrbitingPlanets and OrbitingMoons relation types defined in the vso.xml file.

12 Discover whether an object has children of a certain relation type by implementing the IPluginFactory interface's method.

The SolarSystemFactory example implements hasChildrenInRelation() to determine whether an object has children that relate to it by a given type.

public HasChildrenResult hasChildrenInRelation(String parentType, String parentId, String relationName) {

return HasChildrenResult.Unknown;

}

The possible return values are Yes, No and Unknown.

You have a plug-in factory implementation that defines how Orchestrator finds objects through the plug-in and how it performs operations on those objects.

What to do next

Map the application objects to Orchestrator objects in the vso.xml file.

In document vcenter Orchestrator Developer's Guide (Page 146-149)

Related documents