use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class NifiProcessGroup method validateInputProcessor.
public void validateInputProcessor() {
if (this.errors == null) {
errors = new ArrayList<>();
}
if (processGroupEntity == null) {
processGroupEntity = new ProcessGroupDTO();
processGroupEntity.setName("Process Group");
if (inputProcessor != null) {
processGroupEntity.setId(inputProcessor.getParentGroupId());
}
}
if (this.inputProcessor != null && this.processGroupEntity != null) {
NiFiComponentErrors error = NifiProcessorValidationUtil.getProcessorValidationErrors(this.inputProcessor, false);
if (error != null && !error.getValidationErrors().isEmpty()) {
if (!isErrorAlreadyRecorded(error)) {
errors.add(error);
}
}
}
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class TestFlowBuilder method processGroupDTO.
private ProcessGroupDTO processGroupDTO() {
ProcessGroupDTO groupDTO = new ProcessGroupDTO();
groupDTO.setName("Group " + groupCounter.incrementAndGet());
groupDTO.setId(UUID.randomUUID().toString());
return groupDTO;
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class NifiFlowBuilder method build.
/**
* Build the {@link NifiFlowProcessGroup} from the visited {@link NifiVisitableProcessGroup} returning the simplified graph of objects that make up the flow
*
* @param group the visited process group and its flow connecting processors together
* @return the simplified graph representing the flow starting with the supplied visited process group
*/
public NifiFlowProcessGroup build(NifiVisitableProcessGroup group) {
NifiFlowProcessGroup flowProcessGroup = toFlowProcessGroup(group);
flowProcessGroup.setProcessorMap(cache);
flowProcessGroup.addConnections(group.getConnections());
ProcessGroupDTO groupDTO = group.getParentProcessGroup();
if (groupDTO != null) {
flowProcessGroup.setParentGroupId(groupDTO.getId());
flowProcessGroup.setParentGroupName(groupDTO.getName());
}
flowProcessGroup.assignFlowIds();
return flowProcessGroup;
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class TemplateCreationHelper method createTemporaryTemplateFlow.
/**
* Creates an instance of the supplied template under the temporary inspection group inside its own process group
*
* @param templateId the template to instantiate
* @return the process group holding this template
*/
public ProcessGroupDTO createTemporaryTemplateFlow(@Nonnull final String templateId) {
ProcessGroupDTO temporaryTemplateInspectionGroup = nifiObjectCache.getOrCreateTemporaryTemplateInspectionGroup();
// next create the temp group
snapshotControllerServiceReferences();
ProcessGroupDTO tempGroup = null;
try {
tempGroup = nifiRestClient.processGroups().create(temporaryTemplateInspectionGroup.getId(), "template_" + System.currentTimeMillis());
} catch (NifiComponentNotFoundException e) {
nifiObjectCache.resetTemporaryTemplateInspectionGroup();
tempGroup = nifiRestClient.processGroups().create(temporaryTemplateInspectionGroup.getId(), "template_" + System.currentTimeMillis());
}
TemplateInstance instance = instantiateFlowFromTemplate(tempGroup.getId(), templateId);
FlowSnippetDTO snippet = instance.getFlowSnippetDTO();
identifyNewlyCreatedControllerServiceReferences(instance);
tempGroup.setContents(snippet);
// now delete it
nifiRestClient.processGroups().delete(tempGroup);
cleanupControllerServices();
return tempGroup;
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class TemplateInstanceCreator method createTemplate.
public NifiProcessGroup createTemplate() throws TemplateCreationException {
try {
NifiProcessGroup newProcessGroup = null;
TemplateDTO template = restClient.getTemplateById(templateId);
VersionedProcessGroup versionedProcessGroup = null;
if (template != null) {
TemplateCreationHelper templateCreationHelper = new TemplateCreationHelper(this.restClient);
templateCreationHelper.setTemplateProperties(templateProperties);
String processGroupId = null;
ProcessGroupDTO group = null;
if (isCreateReusableFlow()) {
log.info("Creating a new Reusable flow instance for template: {} ", template.getName());
// 1 get/create the parent "reusable_templates" processgroup
ProcessGroupDTO reusableParentGroup = restClient.getProcessGroupByName("root", TemplateCreationHelper.REUSABLE_TEMPLATES_PROCESS_GROUP_NAME);
if (reusableParentGroup == null) {
reusableParentGroup = restClient.createProcessGroup("root", TemplateCreationHelper.REUSABLE_TEMPLATES_PROCESS_GROUP_NAME);
}
ProcessGroupDTO thisGroup = restClient.getProcessGroupByName(reusableParentGroup.getId(), template.getName());
if (thisGroup != null) {
// version the group
log.info("A previous Process group of with this name {} was found. Versioning it before continuing", thisGroup.getName());
versionedProcessGroup = templateCreationHelper.versionProcessGroup(thisGroup, this.getVersionIdentifier());
}
group = restClient.createProcessGroup(reusableParentGroup.getId(), template.getName());
} else {
String tmpName = template.getName() + "_" + System.currentTimeMillis();
group = restClient.createProcessGroup(tmpName);
log.info("Creating a temporary process group with name {} for template {} ", tmpName, template.getName());
}
processGroupId = group.getId();
if (StringUtils.isNotBlank(processGroupId)) {
// snapshot the existing controller services
templateCreationHelper.snapshotControllerServiceReferences();
log.info("Successfully Snapshot of controller services");
// create the flow from the template
TemplateInstance instance = templateCreationHelper.instantiateFlowFromTemplate(processGroupId, templateId);
FlowSnippetDTO flowSnippetDTO = instance.getFlowSnippetDTO();
log.info("Successfully created the temp flow");
if (this.createReusableFlow) {
ensureInputPortsForReuseableTemplate(processGroupId);
log.info("Reusable flow, input ports created successfully.");
}
// mark the new services that were created as a result of creating the new flow from the template
templateCreationHelper.identifyNewlyCreatedControllerServiceReferences(instance);
ProcessGroupDTO entity = restClient.getProcessGroup(processGroupId, true, true);
// replace static properties and inject values into the flow
List<NifiProperty> processorProperties = NifiPropertyUtil.getProperties(entity, restClient.getPropertyDescriptorTransform());
if (processorProperties != null) {
boolean didReplace = false;
for (NifiProperty property : processorProperties) {
boolean replaced = ConfigurationPropertyReplacer.resolveStaticConfigurationProperty(property, staticConfigPropertyMap);
if (replaced) {
// update the properties that are replaced
if (property.getPropertyDescriptor() != null && StringUtils.isNotBlank(property.getPropertyDescriptor().getIdentifiesControllerService())) {
// verify the property is a valid cs property
String value = property.getValue();
if (templateCreationHelper.getEnabledServiceNameMap().containsKey(value)) {
property.setValue(templateCreationHelper.getEnabledServiceNameMap().get(value).get(0).getId());
}
}
restClient.updateProcessorProperty(property.getProcessGroupId(), property.getProcessorId(), property);
didReplace = true;
}
}
// if we replaced any properties, refetch to get the latest data
if (didReplace) {
entity = restClient.getProcessGroup(processGroupId, true, true);
}
}
// identify the various processors (first level initial processors)
List<ProcessorDTO> inputProcessors = NifiProcessUtil.getInputProcessors(entity);
ProcessorDTO input = null;
List<ProcessorDTO> nonInputProcessors = NifiProcessUtil.getNonInputProcessors(entity);
// if the input is null attempt to get the first input available on the template
if (input == null && inputProcessors != null && !inputProcessors.isEmpty()) {
input = inputProcessors.get(0);
}
log.info("Attempt to update/validate controller services for template.");
// update any references to the controller services and try to assign the value to an enabled service if it is not already
boolean updatedControllerServices = false;
if (input != null) {
log.info("attempt to update controllerservices on {} input processor ", input.getName());
List<NifiProperty> updatedProperties = templateCreationHelper.updateControllerServiceReferences(Lists.newArrayList(inputProcessors), staticConfigPropertyStringMap, instance);
updatedControllerServices = !updatedProperties.isEmpty();
}
log.info("attempt to update controllerservices on {} processors ", (nonInputProcessors != null ? nonInputProcessors.size() : 0));
List<NifiProperty> updatedProperties = templateCreationHelper.updateControllerServiceReferences(nonInputProcessors, staticConfigPropertyStringMap, instance);
if (!updatedControllerServices) {
updatedControllerServices = !updatedProperties.isEmpty();
}
log.info("Controller service validation complete");
// refetch processors for updated errors
entity = restClient.getProcessGroup(processGroupId, true, true);
nonInputProcessors = NifiProcessUtil.getNonInputProcessors(entity);
inputProcessors = NifiProcessUtil.getInputProcessors(entity);
if (inputProcessors != null && !inputProcessors.isEmpty()) {
input = inputProcessors.get(0);
}
// /make the input/output ports in the category group as running
if (isCreateReusableFlow()) {
log.info("Reusable flow, attempt to mark the connection ports as running.");
templateCreationHelper.startProcessGroupAndParentInputPorts(entity);
// templateCreationHelper.markConnectionPortsAsRunning(entity);
log.info("Reusable flow. Successfully marked the ports as running.");
}
newProcessGroup = new NifiProcessGroup(entity, input, nonInputProcessors);
newProcessGroup.setVersionedProcessGroup(versionedProcessGroup);
newProcessGroup.setReusableFlowInstance(isCreateReusableFlow());
if (isCreateReusableFlow()) {
// call listeners notify of before mark as running processing
if (creationCallback != null) {
try {
creationCallback.beforeMarkAsRunning(template.getName(), entity);
} catch (Exception e) {
log.error("Error calling callback beforeMarkAsRunning ", e);
}
}
log.info("Reusable flow, attempt to mark the Processors as running.");
templateCreationHelper.markProcessorsAsRunning(newProcessGroup);
log.info("Reusable flow. Successfully marked the Processors as running.");
// align items
AlignProcessGroupComponents alignProcessGroupComponents = new AlignProcessGroupComponents(restClient.getNiFiRestClient(), entity.getParentGroupId());
alignProcessGroupComponents.autoLayout();
}
templateCreationHelper.cleanupControllerServices();
log.info("Controller service cleanup complete");
List<NifiError> errors = templateCreationHelper.getErrors();
// add any global errors to the object
if (errors != null && !errors.isEmpty()) {
for (NifiError error : errors) {
newProcessGroup.addError(error);
}
}
newProcessGroup.setSuccess(!newProcessGroup.hasFatalErrors());
if (!newProcessGroup.isSuccess()) {
log.info("Errors while importing the template. {} errors found. {}", (errors != null ? errors.size() : 0), (errors != null ? " - " + StringUtils.join(errors, ",") : ""));
} else {
log.info("Success. Finished importing template ");
}
return newProcessGroup;
}
}
} catch (final Exception e) {
if (log.isDebugEnabled() && e instanceof WebApplicationException) {
final Response response = ((WebApplicationException) e).getResponse();
log.debug("NiFi server returned error: {}", response.readEntity(String.class), e);
}
throw new TemplateCreationException("Unable to create the template for the Id of [" + templateId + "]. " + e.getMessage(), e);
}
return null;
}
Aggregations