Search in sources :

Example 6 with ImportComponentOption

use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.

the class ImportReusableTemplate method connect.

private boolean connect() {
    NifiProcessGroup processGroup = this.newTemplateInstance;
    UploadProgressMessage importStatusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Connecting and validating components for " + importTemplate.getTemplateName());
    connectReusableFlow(importStatusMessage, processGroup);
    recreateOutputPortConnections(importStatusMessage, processGroup);
    boolean valid = validateOutputPortConnections(processGroup);
    importStatusMessage.update("Connected and validated components for " + importTemplate.getTemplateName(), valid);
    // create any remote process group ports and connect them on the main NiFi canvas
    if (isClustered()) {
        ImportComponentOption remoteProcessGroupOption = importTemplateOptions.findImportComponentOption(ImportComponent.REMOTE_INPUT_PORT);
        if (remoteProcessGroupOption.isUserAcknowledged() && remoteProcessGroupOption.isShouldImport()) {
            if (remoteProcessGroupOption.getRemoteProcessGroupInputPortsForTemplate(importTemplate.getTemplateName()).stream().anyMatch(inputPort -> inputPort.isSelected())) {
                UploadProgressMessage remoteInputPortsMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Creating remote input port connections for " + remoteProcessGroupOption.getRemoteProcessGroupInputPortsForTemplate(importTemplate.getTemplateName()).stream().filter(inputPort -> inputPort.isSelected()).map(inputPort -> inputPort.getInputPortName()).collect(Collectors.joining(",")));
                valid &= createRemoteInputPorts(remoteInputPortsMessage);
            }
        }
        if (remoteProcessGroupOption.isShouldImport() && remoteProcessGroupOption.isUserAcknowledged()) {
            // identify if the user wished to remove any input ports.
            valid = removeConnectionsAndInputs();
        }
    }
    return valid && newTemplateInstance.isSuccess();
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) UploadProgressService(com.thinkbiganalytics.feedmgr.service.UploadProgressService) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) LoggerFactory(org.slf4j.LoggerFactory) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil) StringUtils(org.apache.commons.lang3.StringUtils) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) NifiFlowUtil(com.thinkbiganalytics.nifi.rest.support.NifiFlowUtil) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) ReusableTemplateCreationCallback(com.thinkbiganalytics.nifi.feedmgr.ReusableTemplateCreationCallback) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) RegisteredTemplateCache(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateCache) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ImportTemplateOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportTemplateOptions) Optional(java.util.Optional) NiFiTemplateImport(com.thinkbiganalytics.feedmgr.service.template.importing.model.NiFiTemplateImport) ImportComponent(com.thinkbiganalytics.feedmgr.rest.ImportComponent) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) HashMap(java.util.HashMap) ImportSection(com.thinkbiganalytics.feedmgr.rest.ImportSection) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) Nullable(javax.annotation.Nullable) NiFiClusterSummary(com.thinkbiganalytics.nifi.rest.model.NiFiClusterSummary) Logger(org.slf4j.Logger) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) TemplateRemoteInputPortConnections(com.thinkbiganalytics.feedmgr.rest.model.TemplateRemoteInputPortConnections) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)

Example 7 with ImportComponentOption

use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.

the class ImportReusableTemplate method createRemoteInputPorts.

private boolean createRemoteInputPorts(UploadProgressMessage remoteInputPortsMessage) {
    ImportComponentOption remoteProcessGroupOption = importTemplateOptions.findImportComponentOption(ImportComponent.REMOTE_INPUT_PORT);
    String rootProcessGroupId = templateConnectionUtil.getRootProcessGroup().getId();
    String reusableTemplateProcessGroupId = templateConnectionUtil.getReusableTemplateProcessGroupId();
    Map<String, PortDTO> reusableTemplateCategoryPorts = getReusableTemplateCategoryProcessGroup().getContents().getInputPorts().stream().collect(Collectors.toMap(p -> p.getName(), p -> p));
    StringBuffer connectedStr = new StringBuffer("");
    remoteProcessGroupOption.getRemoteProcessGroupInputPortsForTemplate(importTemplate.getTemplateName()).stream().filter(r -> r.isSelected() && !r.isExisting()).forEach(r -> {
        // check/create the port at the parent canvas
        PortDTO portDTO = new PortDTO();
        portDTO.setName(r.getInputPortName());
        portDTO.setType(NifiConstants.INPUT_PORT);
        portDTO.setState(NifiProcessUtil.PROCESS_STATE.STOPPED.name());
        PortDTO newInputPort = nifiRestClient.getNiFiRestClient().processGroups().createInputPort(rootProcessGroupId, portDTO);
        getItemsCreated().addCreatedRemoteInputPort(newInputPort);
        PortDTO reusableTemplatePort = reusableTemplateCategoryPorts.get(r.getInputPortName());
        // connect this to the Reusable Template input port with the same name
        ConnectableDTO source = new ConnectableDTO();
        source.setGroupId(rootProcessGroupId);
        source.setId(newInputPort.getId());
        source.setName(newInputPort.getName());
        source.setType(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name());
        ConnectableDTO dest = new ConnectableDTO();
        dest.setGroupId(reusableTemplateProcessGroupId);
        dest.setName(r.getInputPortName());
        dest.setId(reusableTemplatePort.getId());
        dest.setType(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name());
        ConnectionDTO connectionDTO = nifiRestClient.getNiFiRestClient().processGroups().createConnection(rootProcessGroupId, source, dest);
        getItemsCreated().addCreatedRemoteInputPortConnection(connectionDTO);
        if (connectedStr.length() != 0) {
            connectedStr.append(",");
        } else {
            connectedStr.append("Created ");
        }
        connectedStr.append(r.getInputPortName());
        remoteInputPortsMessage.update(connectedStr.toString());
    });
    if (connectedStr.length() != 0) {
        connectedStr.append(" as remote input ports");
    }
    if (connectedStr.length() > 0) {
        remoteInputPortsMessage.update(connectedStr.toString(), true);
    } else {
        remoteInputPortsMessage.complete(true);
    }
    return true;
}
Also used : UploadProgressService(com.thinkbiganalytics.feedmgr.service.UploadProgressService) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) LoggerFactory(org.slf4j.LoggerFactory) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil) StringUtils(org.apache.commons.lang3.StringUtils) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) NifiFlowUtil(com.thinkbiganalytics.nifi.rest.support.NifiFlowUtil) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) ReusableTemplateCreationCallback(com.thinkbiganalytics.nifi.feedmgr.ReusableTemplateCreationCallback) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) RegisteredTemplateCache(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateCache) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ImportTemplateOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportTemplateOptions) Optional(java.util.Optional) NiFiTemplateImport(com.thinkbiganalytics.feedmgr.service.template.importing.model.NiFiTemplateImport) ImportComponent(com.thinkbiganalytics.feedmgr.rest.ImportComponent) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) HashMap(java.util.HashMap) ImportSection(com.thinkbiganalytics.feedmgr.rest.ImportSection) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) Nullable(javax.annotation.Nullable) NiFiClusterSummary(com.thinkbiganalytics.nifi.rest.model.NiFiClusterSummary) Logger(org.slf4j.Logger) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) TemplateRemoteInputPortConnections(com.thinkbiganalytics.feedmgr.rest.model.TemplateRemoteInputPortConnections) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) PortDTO(org.apache.nifi.web.api.dto.PortDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Example 8 with ImportComponentOption

use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.

the class ImportReusableTemplate method importTemplate.

public boolean importTemplate() {
    boolean validReusableTemplate = importIntoNiFiAndCreateInstance();
    // Check and set the Remote PRocess group settings.
    // use this later to determine if we need to create NiFi Flow input ports connected to this template
    ImportComponentOption remoteProcessGroupOption = importTemplateOptions.findImportComponentOption(ImportComponent.REMOTE_INPUT_PORT);
    if (validReusableTemplate && remoteProcessGroupOption.isShouldImport()) {
        validReusableTemplate &= validateRemoteInputPorts(remoteProcessGroupOption);
    }
    if (validReusableTemplate) {
        validReusableTemplate = connectAndValidate();
    }
    if (validReusableTemplate) {
        validReusableTemplate = validateInstance();
    }
    if (validReusableTemplate) {
        nifiRestClient.markConnectionPortsAsRunning(importTemplate.getTemplateResults().getProcessGroupEntity());
        // remove previous template
        cleanup();
    } else {
        rollback();
    }
    return validReusableTemplate;
}
Also used : ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption)

Example 9 with ImportComponentOption

use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.

the class ImportTemplateArchive method connectReusableTemplates.

private boolean connectReusableTemplates() {
    // now connect these
    boolean validConnections = true;
    for (ImportReusableTemplate importReusableTemplate : importedReusableTemplates) {
        ImportComponentOption remoteProcessGroupOption = importReusableTemplate.getImportTemplateOptions().findImportComponentOption(ImportComponent.REMOTE_INPUT_PORT);
        // first validate the remote inputs if they exist
        if (validConnections && remoteProcessGroupOption.isShouldImport()) {
            validConnections &= importReusableTemplate.validateRemoteInputPorts(remoteProcessGroupOption);
            if (importReusableTemplate.getImportTemplate().isRemoteProcessGroupInputPortsNeeded()) {
                importReusableTemplate.getImportTemplate().getRemoteProcessGroupInputPortNames().stream().forEach(connectionInfo -> this.importTemplate.addRemoteProcessGroupInputPort(connectionInfo));
                this.importTemplate.setRemoteProcessGroupInputPortsNeeded(true);
            }
        }
    }
    if (validConnections) {
        for (ImportReusableTemplate importReusableTemplate : importedReusableTemplates) {
            validConnections &= importReusableTemplate.connectAndValidate();
            if (importReusableTemplate.getImportTemplate().isReusableFlowOutputPortConnectionsNeeded()) {
                importReusableTemplate.getImportTemplate().getReusableTemplateConnections().stream().forEach(connectionInfo -> this.importTemplate.addReusableTemplateConnection(connectionInfo));
                this.importTemplate.setReusableFlowOutputPortConnectionsNeeded(true);
            }
            if (!validConnections) {
                break;
            }
        }
    }
    if (validConnections) {
        for (ImportReusableTemplate importReusableTemplate : importedReusableTemplates) {
            validConnections &= importReusableTemplate.validateInstance();
            if (importReusableTemplate.getImportTemplate().isReusableFlowOutputPortConnectionsNeeded()) {
                // importReusableTemplate.getImportTemplate().getReusableTemplateConnections().stream().forEach(connectionInfo -> this.importTemplate.addReusableTemplateConnection(connectionInfo));
                this.importTemplate.setReusableFlowOutputPortConnectionsNeeded(true);
            }
            if (!validConnections) {
                break;
            }
        }
    }
    importTemplate.setSuccess(validConnections);
    return validConnections;
}
Also used : ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption)

Example 10 with ImportComponentOption

use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.

the class ImportTemplateArchive method registerTemplate.

/**
 * Register the template with the metadata and save it
 *
 * @param importTemplate the template data to import
 * @param importOptions  user options about what/how it should be imported
 * @return the registered template that was saved
 */
private RegisteredTemplate registerTemplate(ImportTemplate importTemplate, ImportTemplateOptions importOptions) {
    RegisteredTemplate template = importTemplate.getTemplateToImport();
    ImportComponentOption registeredTemplateOption = importOptions.findImportComponentOption(ImportComponent.TEMPLATE_DATA);
    if (registeredTemplateOption.isValidForImport()) {
        UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(importOptions.getUploadKey(), "Registering template " + template.getTemplateName() + " with Kylo metadata.");
        try {
            importTemplate.setNifiTemplateId(template.getNifiTemplateId());
            // register it in the system
            metadataService.registerTemplate(template);
            // get the new template
            template = registeredTemplateService.findRegisteredTemplate(new RegisteredTemplateRequest.Builder().templateId(template.getId()).templateName(template.getTemplateName()).build());
            importTemplate.setTemplateId(template.getId());
            statusMessage.update("Registered template with Kylo metadata.", true);
        } catch (Exception e) {
            importTemplate.setSuccess(false);
            Throwable root = ExceptionUtils.getRootCause(e);
            String msg = root != null ? root.getMessage() : e.getMessage();
            importTemplate.getTemplateResults().addError(NifiError.SEVERITY.WARN, "Error registering the template " + template.getTemplateName() + " in the Kylo metadata. " + msg, "");
            statusMessage.update("Error registering template with Kylo metadata. " + msg, false);
        }
    }
    return template;
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest)

Aggregations

ImportComponentOption (com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption)24 UploadProgressMessage (com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage)14 ImportTemplate (com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate)11 ImportComponent (com.thinkbiganalytics.feedmgr.rest.ImportComponent)9 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)9 HashSet (java.util.HashSet)9 List (java.util.List)9 Optional (java.util.Optional)9 Set (java.util.Set)9 Collectors (java.util.stream.Collectors)9 StringUtils (org.apache.commons.lang3.StringUtils)9 RemoteProcessGroupInputPort (com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort)8 ReusableTemplateConnectionInfo (com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo)8 NifiError (com.thinkbiganalytics.nifi.rest.model.NifiError)8 NifiProcessGroup (com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)8 IOException (java.io.IOException)8 Map (java.util.Map)8 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)8 ImportTemplateOptions (com.thinkbiganalytics.feedmgr.rest.model.ImportTemplateOptions)7 ImportSection (com.thinkbiganalytics.feedmgr.rest.ImportSection)6