Search in sources :

Example 1 with UiExtensionMapping

use of org.apache.nifi.ui.extension.UiExtensionMapping in project nifi by apache.

the class ControllerServiceResource method populateRemainingControllerServiceContent.

/**
 * Populates the uri for the specified controller service.
 */
public ControllerServiceDTO populateRemainingControllerServiceContent(final ControllerServiceDTO controllerService) {
    final BundleDTO bundle = controllerService.getBundle();
    // see if this processor has any ui extensions
    final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions");
    if (uiExtensionMapping.hasUiExtension(controllerService.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion())) {
        final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(controllerService.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion());
        for (final UiExtension uiExtension : uiExtensions) {
            if (UiExtensionType.ControllerServiceConfiguration.equals(uiExtension.getExtensionType())) {
                controllerService.setCustomUiUrl(uiExtension.getContextPath() + "/configure");
            }
        }
    }
    return controllerService;
}
Also used : UiExtension(org.apache.nifi.ui.extension.UiExtension) UiExtensionMapping(org.apache.nifi.ui.extension.UiExtensionMapping) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO)

Example 2 with UiExtensionMapping

use of org.apache.nifi.ui.extension.UiExtensionMapping in project nifi by apache.

the class ProcessorResource method populateRemainingProcessorContent.

/**
 * Populate the uri's for the specified processor and its relationships.
 */
public ProcessorDTO populateRemainingProcessorContent(ProcessorDTO processor) {
    // get the config details and see if there is a custom ui for this processor type
    ProcessorConfigDTO config = processor.getConfig();
    if (config != null) {
        // consider legacy custom ui fist
        String customUiUrl = servletContext.getInitParameter(processor.getType());
        if (StringUtils.isNotBlank(customUiUrl)) {
            config.setCustomUiUrl(customUiUrl);
        } else {
            final BundleDTO bundle = processor.getBundle();
            // see if this processor has any ui extensions
            final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions");
            if (uiExtensionMapping.hasUiExtension(processor.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion())) {
                final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(processor.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion());
                for (final UiExtension uiExtension : uiExtensions) {
                    if (UiExtensionType.ProcessorConfiguration.equals(uiExtension.getExtensionType())) {
                        config.setCustomUiUrl(uiExtension.getContextPath() + "/configure");
                    }
                }
            }
        }
    }
    return processor;
}
Also used : ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) UiExtension(org.apache.nifi.ui.extension.UiExtension) UiExtensionMapping(org.apache.nifi.ui.extension.UiExtensionMapping) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO)

Example 3 with UiExtensionMapping

use of org.apache.nifi.ui.extension.UiExtensionMapping in project nifi by apache.

the class NiFiTestServer method startServer.

public void startServer() throws Exception {
    jetty.start();
    // ensure the ui extensions are set
    webappContext.getServletContext().setAttribute("nifi-ui-extensions", new UiExtensionMapping(Collections.EMPTY_MAP));
}
Also used : UiExtensionMapping(org.apache.nifi.ui.extension.UiExtensionMapping)

Example 4 with UiExtensionMapping

use of org.apache.nifi.ui.extension.UiExtensionMapping in project nifi by apache.

the class JettyServer method loadWars.

private Handler loadWars(final Set<Bundle> bundles) {
    // load WARs
    final Map<File, Bundle> warToBundleLookup = findWars(bundles);
    // locate each war being deployed
    File webUiWar = null;
    File webApiWar = null;
    File webErrorWar = null;
    File webDocsWar = null;
    File webContentViewerWar = null;
    List<File> otherWars = new ArrayList<>();
    for (File war : warToBundleLookup.keySet()) {
        if (war.getName().toLowerCase().startsWith("nifi-web-api")) {
            webApiWar = war;
        } else if (war.getName().toLowerCase().startsWith("nifi-web-error")) {
            webErrorWar = war;
        } else if (war.getName().toLowerCase().startsWith("nifi-web-docs")) {
            webDocsWar = war;
        } else if (war.getName().toLowerCase().startsWith("nifi-web-content-viewer")) {
            webContentViewerWar = war;
        } else if (war.getName().toLowerCase().startsWith("nifi-web")) {
            webUiWar = war;
        } else {
            otherWars.add(war);
        }
    }
    // ensure the required wars were found
    if (webUiWar == null) {
        throw new RuntimeException("Unable to load nifi-web WAR");
    } else if (webApiWar == null) {
        throw new RuntimeException("Unable to load nifi-web-api WAR");
    } else if (webDocsWar == null) {
        throw new RuntimeException("Unable to load nifi-web-docs WAR");
    } else if (webErrorWar == null) {
        throw new RuntimeException("Unable to load nifi-web-error WAR");
    } else if (webContentViewerWar == null) {
        throw new RuntimeException("Unable to load nifi-web-content-viewer WAR");
    }
    // handlers for each war and init params for the web api
    final HandlerCollection handlers = new HandlerCollection();
    final Map<String, String> mimeMappings = new HashMap<>();
    final ClassLoader frameworkClassLoader = getClass().getClassLoader();
    final ClassLoader jettyClassLoader = frameworkClassLoader.getParent();
    // deploy the other wars
    if (CollectionUtils.isNotEmpty(otherWars)) {
        // hold onto to the web contexts for all ui extensions
        componentUiExtensionWebContexts = new ArrayList<>();
        contentViewerWebContexts = new ArrayList<>();
        // ui extension organized by component type
        final Map<String, List<UiExtension>> componentUiExtensionsByType = new HashMap<>();
        for (File war : otherWars) {
            // identify all known extension types in the war
            final Map<UiExtensionType, List<String>> uiExtensionInWar = new HashMap<>();
            identifyUiExtensionsForComponents(uiExtensionInWar, war);
            // only include wars that are for custom processor ui's
            if (!uiExtensionInWar.isEmpty()) {
                // get the context path
                String warName = StringUtils.substringBeforeLast(war.getName(), ".");
                String warContextPath = String.format("/%s", warName);
                // get the classloader for this war
                ClassLoader narClassLoaderForWar = warToBundleLookup.get(war).getClassLoader();
                // this should never be null
                if (narClassLoaderForWar == null) {
                    narClassLoaderForWar = jettyClassLoader;
                }
                // create the extension web app context
                WebAppContext extensionUiContext = loadWar(war, warContextPath, narClassLoaderForWar);
                // create the ui extensions
                for (final Map.Entry<UiExtensionType, List<String>> entry : uiExtensionInWar.entrySet()) {
                    final UiExtensionType extensionType = entry.getKey();
                    final List<String> types = entry.getValue();
                    if (UiExtensionType.ContentViewer.equals(extensionType)) {
                        // consider each content type identified
                        for (final String contentType : types) {
                            // map the content type to the context path
                            mimeMappings.put(contentType, warContextPath);
                        }
                        // this ui extension provides a content viewer
                        contentViewerWebContexts.add(extensionUiContext);
                    } else {
                        // consider each component type identified
                        for (final String componentTypeCoordinates : types) {
                            logger.info(String.format("Loading UI extension [%s, %s] for %s", extensionType, warContextPath, componentTypeCoordinates));
                            // record the extension definition
                            final UiExtension uiExtension = new UiExtension(extensionType, warContextPath);
                            // create if this is the first extension for this component type
                            List<UiExtension> componentUiExtensionsForType = componentUiExtensionsByType.get(componentTypeCoordinates);
                            if (componentUiExtensionsForType == null) {
                                componentUiExtensionsForType = new ArrayList<>();
                                componentUiExtensionsByType.put(componentTypeCoordinates, componentUiExtensionsForType);
                            }
                            // see if there is already a ui extension of this same time
                            if (containsUiExtensionType(componentUiExtensionsForType, extensionType)) {
                                throw new IllegalStateException(String.format("Encountered duplicate UI for %s", componentTypeCoordinates));
                            }
                            // record this extension
                            componentUiExtensionsForType.add(uiExtension);
                        }
                        // this ui extension provides a component custom ui
                        componentUiExtensionWebContexts.add(extensionUiContext);
                    }
                }
                // include custom ui web context in the handlers
                handlers.addHandler(extensionUiContext);
            }
        }
        // record all ui extensions to give to the web api
        componentUiExtensions = new UiExtensionMapping(componentUiExtensionsByType);
    } else {
        componentUiExtensions = new UiExtensionMapping(Collections.EMPTY_MAP);
    }
    // load the web ui app
    final WebAppContext webUiContext = loadWar(webUiWar, "/nifi", frameworkClassLoader);
    webUiContext.getInitParams().put("oidc-supported", String.valueOf(props.isOidcEnabled()));
    webUiContext.getInitParams().put("knox-supported", String.valueOf(props.isKnoxSsoEnabled()));
    handlers.addHandler(webUiContext);
    // load the web api app
    webApiContext = loadWar(webApiWar, "/nifi-api", frameworkClassLoader);
    handlers.addHandler(webApiContext);
    // load the content viewer app
    webContentViewerContext = loadWar(webContentViewerWar, "/nifi-content-viewer", frameworkClassLoader);
    webContentViewerContext.getInitParams().putAll(mimeMappings);
    handlers.addHandler(webContentViewerContext);
    // create a web app for the docs
    final String docsContextPath = "/nifi-docs";
    // load the documentation war
    webDocsContext = loadWar(webDocsWar, docsContextPath, frameworkClassLoader);
    // overlay the actual documentation
    final ContextHandlerCollection documentationHandlers = new ContextHandlerCollection();
    documentationHandlers.addHandler(createDocsWebApp(docsContextPath));
    documentationHandlers.addHandler(webDocsContext);
    handlers.addHandler(documentationHandlers);
    // load the web error app
    final WebAppContext webErrorContext = loadWar(webErrorWar, "/", frameworkClassLoader);
    webErrorContext.getInitParams().put("whitelistedContextPaths", props.getWhitelistedContextPaths());
    handlers.addHandler(webErrorContext);
    // deploy the web apps
    return gzip(handlers);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) UiExtension(org.apache.nifi.ui.extension.UiExtension) WebAppClassLoader(org.eclipse.jetty.webapp.WebAppClassLoader) UiExtensionMapping(org.apache.nifi.ui.extension.UiExtensionMapping) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) List(java.util.List) ArrayList(java.util.ArrayList) HandlerList(org.eclipse.jetty.server.handler.HandlerList) UiExtensionType(org.apache.nifi.web.UiExtensionType) Bundle(org.apache.nifi.bundle.Bundle) JarFile(java.util.jar.JarFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with UiExtensionMapping

use of org.apache.nifi.ui.extension.UiExtensionMapping in project nifi by apache.

the class ReportingTaskResource method populateRemainingReportingTaskContent.

/**
 * Populates the uri for the specified reporting task.
 */
public ReportingTaskDTO populateRemainingReportingTaskContent(final ReportingTaskDTO reportingTask) {
    final BundleDTO bundle = reportingTask.getBundle();
    // see if this processor has any ui extensions
    final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions");
    if (uiExtensionMapping.hasUiExtension(reportingTask.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion())) {
        final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(reportingTask.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion());
        for (final UiExtension uiExtension : uiExtensions) {
            if (UiExtensionType.ReportingTaskConfiguration.equals(uiExtension.getExtensionType())) {
                reportingTask.setCustomUiUrl(uiExtension.getContextPath() + "/configure");
            }
        }
    }
    return reportingTask;
}
Also used : UiExtension(org.apache.nifi.ui.extension.UiExtension) UiExtensionMapping(org.apache.nifi.ui.extension.UiExtensionMapping) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO)

Aggregations

UiExtensionMapping (org.apache.nifi.ui.extension.UiExtensionMapping)5 UiExtension (org.apache.nifi.ui.extension.UiExtension)4 BundleDTO (org.apache.nifi.web.api.dto.BundleDTO)3 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 JarFile (java.util.jar.JarFile)1 Bundle (org.apache.nifi.bundle.Bundle)1 UiExtensionType (org.apache.nifi.web.UiExtensionType)1 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)1 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)1 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)1 HandlerList (org.eclipse.jetty.server.handler.HandlerList)1 WebAppClassLoader (org.eclipse.jetty.webapp.WebAppClassLoader)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1