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();
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations