Framework Services
The View framework exposes server-side services through ViewContext and related interfaces under ambari-views/src/main/java/org/apache/ambari/view.
ViewContext
View server resources receive a ViewContext. It provides the authenticated users, View definition, instance name and properties, instance data, Ambari properties, resource providers, stream providers, and the View controller.
@Inject
ViewContext context;
Use getUsername(), getLoggedinUser(), and hasPermission() for identity and permission checks. Do not treat client-side visibility as authorization; the server must enforce access to View resources and Web contexts.
Instance Data
putInstanceData, getInstanceData, and removeInstanceData store lightweight key/value data scoped to a View instance and user. This is suitable for preferences and other small state, not metric history or large documents.
viewContext.putInstanceData("key", "value");
String value = viewContext.getInstanceData("key");
Calls without an associated instance can fail according to the ViewContext contract. Handle validation and persistence errors explicitly.
Resource Providers
getResourceProvider(type) returns a provider for a resource declared in view.xml. The ResourceProvider interface defines read, create, update, and delete operations and the corresponding resource/error contracts. Providers are server-side endpoints used by the hosted View application.
Framework Events
An implementation of View can receive lifecycle callbacks:
| Callback | Meaning |
|---|---|
onDeploy | A View version was deployed. |
onCreate | A View instance was created. |
onUpdate | A View instance definition was updated. |
onDestroy | A View instance was destroyed. |
Register the implementation with <view-class> and keep callbacks safe to retry. Deployment callbacks are server operations and are independent of a browser iframe.
View Events
The View controller can register listeners and fire events between Views. Address listeners by View name, or by View name and version, according to the ViewController contract. Event communication does not replace REST authorization or instance-data scoping.