Search in sources :

Example 21 with UploadProgressMessage

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

the class AbstractImportTemplateRoutine method importIntoNiFiAndCreateInstance.

public boolean importIntoNiFiAndCreateInstance() {
    UploadProgressMessage importStatusMessage = start();
    this.niFiTemplateImport = importIntoNiFi(importTemplate, importTemplateOptions);
    uploadProgressService.completeSection(importTemplateOptions, ImportSection.Section.IMPORT_NIFI_TEMPLATE);
    this.newTemplateInstance = create(this.niFiTemplateImport, importStatusMessage);
    importTemplate.setSuccess(newTemplateInstance.isSuccess());
    importStatusMessage.update("Created template instance for " + importTemplate.getTemplateName(), importTemplate.isSuccess());
    uploadProgressService.completeSection(importTemplateOptions, ImportSection.Section.CREATE_NIFI_INSTANCE);
    return importTemplate.isSuccess();
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage)

Example 22 with UploadProgressMessage

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

the class AbstractImportTemplateRoutine method restoreOldTemplateXml.

protected UploadProgressMessage restoreOldTemplateXml() {
    UploadProgressMessage rollbackMessage = uploadProgressService.addUploadStatus(importTemplate.getImportOptions().getUploadKey(), "Attempting to rollback the template xml in NiFi " + importTemplate.getTemplateName());
    if (niFiTemplateImport != null) {
        TemplateDTO dto = niFiTemplateImport.getDto();
        String oldTemplateXml = niFiTemplateImport.getOldTemplateXml();
        log.error("ERROR! This template is NOT VALID Nifi Template: {} for file {}.  Errors are: {} ", importTemplate.getTemplateName(), importTemplate.getFileName(), importTemplate.getTemplateResults().getAllErrors());
        // delete this template
        importTemplate.setSuccess(false);
        // delete the template from NiFi
        nifiRestClient.deleteTemplate(dto.getId());
        // restore old template
        if (oldTemplateXml != null) {
            UploadProgressMessage progressMessage = uploadProgressService.addUploadStatus(importTemplate.getImportOptions().getUploadKey(), "Attempting to restore old template xml for: " + importTemplate.getTemplateName());
            log.info("Rollback Nifi: Attempt to restore old template xml ");
            nifiRestClient.importTemplate(oldTemplateXml);
            log.info("Rollback Nifi: restored old template xml ");
            progressMessage.update("Rollback Status: Restored old template xml for " + importTemplate.getTemplateName(), true);
        }
    }
    return rollbackMessage;
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO)

Example 23 with UploadProgressMessage

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

the class ImportFeedTemplateXml method rollback.

public boolean rollback() {
    UploadProgressMessage rollbackStatus = super.restoreOldTemplateXml();
    rollbackStatus.complete(true);
    return true;
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage)

Example 24 with UploadProgressMessage

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

the class ImportReusableTemplate method validateInstance.

public boolean validateInstance() {
    boolean valid = importTemplate.getTemplateResults().isSuccess() && importTemplate.isValid() && !importTemplate.isReusableFlowOutputPortConnectionsNeeded();
    importTemplate.setSuccess(valid);
    if (importTemplate.isReusableFlowOutputPortConnectionsNeeded()) {
        uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Additional Port Connection information is necessary for the template " + importTemplate.getTemplateName(), true, false);
    }
    uploadProgressService.completeSection(importTemplateOptions, ImportSection.Section.IMPORT_REUSABLE_TEMPLATE);
    if (valid) {
        // start all the connections we created
        List<ConnectionDTO> createdConnections = getConnections();
        if (!createdConnections.isEmpty()) {
            UploadProgressMessage message = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Verify and start all input/output port connections for the template " + importTemplate.getTemplateName());
            getConnections().stream().forEach(connectionDTO -> {
                // verify the Source is started
                ConnectableDTO connectableDTO = connectionDTO.getSource();
                boolean started = startConnectablePorts(connectableDTO);
                // verify the Destination is started
                connectableDTO = connectionDTO.getDestination();
                started &= startConnectablePorts(connectableDTO);
                if (!started) {
                    importTemplate.setSuccess(false);
                }
            });
            message.complete(importTemplate.isSuccess());
        }
    }
    return valid;
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Example 25 with UploadProgressMessage

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

the class ImportReusableTemplate method rollbackTemplateImportInNifi.

/**
 * Restore the previous Template back to Nifi
 */
private void rollbackTemplateImportInNifi() {
    UploadProgressMessage rollbackMessage = restoreOldTemplateXml();
    // If we are working with a reusable flow we need to recreate the old one
    if (importTemplate.getTemplateResults() != null && importTemplate.getTemplateResults().isReusableFlowInstance()) {
        UploadProgressMessage progressMessage = uploadProgressService.addUploadStatus(importTemplate.getImportOptions().getUploadKey(), "Attempting to restore old instance for: " + importTemplate.getTemplateName());
        VersionedProcessGroup versionedProcessGroup = null;
        if (importTemplate.getTemplateResults().getVersionedProcessGroup() != null) {
            versionedProcessGroup = importTemplate.getTemplateResults().getVersionedProcessGroup();
        }
        // rename the one we created to a temp name
        ProcessGroupDTO groupDTO = nifiRestClient.getNiFiRestClient().processGroups().findById(importTemplate.getTemplateResults().getProcessGroupEntity().getId(), false, false).orElse(null);
        if (groupDTO != null) {
            String tmpName = groupDTO.getName() + "- " + System.currentTimeMillis();
            groupDTO.setName(tmpName);
            nifiRestClient.getNiFiRestClient().processGroups().update(groupDTO);
            log.info("Rollback Template: {}.  Renamed template instance that was just created to a temporary name of {}.  This will get deleted later. ", importTemplate.getTemplateName(), tmpName);
        }
        if (versionedProcessGroup != null) {
            progressMessage.update("Rollback Status: Attempting to initialize and verify prior template instance for " + importTemplate.getTemplateName());
            // rename the versioned one back
            ProcessGroupDTO oldProcessGroup = nifiRestClient.getNiFiRestClient().processGroups().findById(versionedProcessGroup.getProcessGroupPriorToVersioning().getId(), true, true).orElse(null);
            if (oldProcessGroup != null) {
                oldProcessGroup.setName(versionedProcessGroup.getProcessGroupName());
                nifiRestClient.getNiFiRestClient().processGroups().update(oldProcessGroup);
                progressMessage.update("Rollback Status: Renamed template process group " + versionedProcessGroup.getVersionedProcessGroupName() + " back to " + versionedProcessGroup.getProcessGroupName());
            }
            // add back in the connections
            List<ConnectionDTO> createdConnections = new ArrayList<>();
            List<ConnectionDTO> connections = versionedProcessGroup.getDeletedInputPortConnections();
            if (connections != null) {
                connections.stream().forEach(connectionDTO -> {
                    createdConnections.add(nifiRestClient.getNiFiRestClient().processGroups().createConnection(connectionDTO.getParentGroupId(), connectionDTO.getSource(), connectionDTO.getDestination()));
                });
                uploadProgressService.addUploadStatus(importTemplate.getImportOptions().getUploadKey(), "Rollback Status: Recreated " + createdConnections.size() + " connections ", true, true);
            }
            List<ProcessorDTO> inputs = versionedProcessGroup.getInputProcessorsPriorToDisabling();
            if (inputs != null) {
                // update the state
                progressMessage.update("Rollback Status: Marking the process group " + versionedProcessGroup.getProcessGroupName() + " as running");
            }
        }
        if (groupDTO != null) {
            progressMessage.update("Rollback Status: Removing invalid template instance process group:  " + groupDTO.getName());
            // delete the new one
            try {
                nifiRestClient.removeProcessGroup(groupDTO.getId(), groupDTO.getParentGroupId());
            } catch (Exception e) {
                log.error("Error trying to remove invalid template instance {}", groupDTO.getName(), e);
            }
            Optional<ProcessGroupDTO> deletedGroup = nifiRestClient.getNiFiRestClient().processGroups().findById(groupDTO.getId(), false, false);
            if (deletedGroup.isPresent()) {
                progressMessage.update("Rollback Status: Failure", false);
                rollbackMessage.update("Rollback Unsuccessful!!  The invalid group " + deletedGroup.get().getName() + " still exists.  You will need to login to NiFi and verify your reusable templates are correct!", false);
            } else {
                String message = "Rollback Status: Success.";
                if (versionedProcessGroup != null) {
                    message += " Restored '" + versionedProcessGroup.getVersionedProcessGroupName() + "' back to '" + importTemplate.getTemplateName() + "'";
                }
                progressMessage.update(message, true);
                rollbackMessage.update("Rollback Successful!", true);
            }
        }
    } else {
        rollbackMessage.update("Rollback Successful!", true);
    }
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) ArrayList(java.util.ArrayList) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)

Aggregations

UploadProgressMessage (com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage)29 ImportComponentOption (com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption)16 ImportTemplate (com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate)10 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)9 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)9 ImportComponent (com.thinkbiganalytics.feedmgr.rest.ImportComponent)8 ImportSection (com.thinkbiganalytics.feedmgr.rest.ImportSection)8 ImportTemplateOptions (com.thinkbiganalytics.feedmgr.rest.model.ImportTemplateOptions)8 UploadProgressService (com.thinkbiganalytics.feedmgr.service.UploadProgressService)8 RegisteredTemplateService (com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService)8 LegacyNifiRestClient (com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient)8 AccessController (com.thinkbiganalytics.security.AccessController)8 Collections (java.util.Collections)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Inject (javax.inject.Inject)8 StringUtils (org.apache.commons.lang3.StringUtils)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)7