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