use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class NifiIntegrationRestController method autoAlign.
@GET
@Path("/auto-align/{processGroupId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Organizes the components of the specified process group.")
@ApiResponses(@ApiResponse(code = 200, message = "The result of the operation.", response = RestResponseStatus.class))
public Response autoAlign(@PathParam("processGroupId") String processGroupId) {
accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ADMIN_FEEDS);
RestResponseStatus status;
if ("all".equals(processGroupId)) {
AlignNiFiComponents alignNiFiComponents = new AlignNiFiComponents();
alignNiFiComponents.setNiFiRestClient(legacyNifiRestClient.getNiFiRestClient());
alignNiFiComponents.autoLayout();
String message = "";
if (alignNiFiComponents.isAligned()) {
message = "Aligned All of NiFi. " + alignNiFiComponents.getAlignedProcessGroups() + " process groups were aligned ";
} else {
message = "Alignment failed while attempting to align all of NiFi. " + alignNiFiComponents.getAlignedProcessGroups() + " were successfully aligned. Please look at the logs for more information";
}
status = new RestResponseStatus.ResponseStatusBuilder().message(message).buildSuccess();
} else {
AlignProcessGroupComponents alignProcessGroupComponents = new AlignProcessGroupComponents(legacyNifiRestClient.getNiFiRestClient(), processGroupId);
ProcessGroupDTO alignedGroup = alignProcessGroupComponents.autoLayout();
String message = "";
if (alignProcessGroupComponents.isAligned()) {
message = "Aligned " + alignedGroup.getContents().getProcessGroups().size() + " process groups under " + alignedGroup.getName();
} else {
message = "Alignment failed for process group " + processGroupId + ". Please look at the logs for more information";
}
status = new RestResponseStatus.ResponseStatusBuilder().message(message).buildSuccess();
}
return Response.ok(status).build();
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class DefaultNiFiFlowVisitorClient method getTemplateFeedFlow.
public NifiFlowProcessGroup getTemplateFeedFlow(TemplateDTO template) {
ProcessGroupDTO parentProcessGroup = new ProcessGroupDTO();
parentProcessGroup.setId(UUID.randomUUID().toString());
parentProcessGroup.setParentGroupId(UUID.randomUUID().toString());
parentProcessGroup.setName(template.getName());
parentProcessGroup.setContents(template.getSnippet());
NifiConnectionOrderVisitorCache cache = new NifiConnectionOrderVisitorCache();
Collection<ProcessGroupDTO> groups = NifiProcessUtil.getProcessGroups(parentProcessGroup);
cache.add(parentProcessGroup);
// add the snippet as its own process group
if (template.getSnippet().getProcessors() != null) {
// find the first processor and get its parent group id
Optional<ProcessorDTO> firstProcessor = template.getSnippet().getProcessors().stream().findFirst();
if (firstProcessor.isPresent()) {
String groupId = firstProcessor.get().getParentGroupId();
ProcessGroupDTO snippetGroup = new ProcessGroupDTO();
snippetGroup.setId(groupId);
snippetGroup.setParentGroupId(template.getGroupId());
snippetGroup.setContents(template.getSnippet());
cache.add(snippetGroup);
}
}
if (groups != null) {
groups.stream().forEach(group -> cache.add(group));
}
// add any remote ProcessGroups
if (template.getSnippet().getRemoteProcessGroups() != null) {
template.getSnippet().getRemoteProcessGroups().stream().forEach(remoteProcessGroupDTO -> cache.add(remoteProcessGroupDTO));
}
NifiVisitableProcessGroup visitableGroup = getFlowOrder(parentProcessGroup, cache, false);
NifiFlowProcessGroup flow = new NifiFlowBuilder().build(visitableGroup);
return flow;
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class LegacyNifiRestClient method getPropertiesForTemplateByName.
/**
* Expose all Properties for a given Template as parameters for external use If template is not found it will return an Empty ArrayList()
*/
public List<NifiProperty> getPropertiesForTemplateByName(String templateName) {
TemplateDTO dto = getTemplateByName(templateName);
if (dto != null) {
// populate the snippet
dto = getTemplateById(dto.getId());
}
ProcessGroupDTO rootProcessGroup = getProcessGroup("root", false, false);
return NifiPropertyUtil.getPropertiesForTemplate(rootProcessGroup, dto, propertyDescriptorTransform);
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class LegacyNifiRestClient method startProcessGroupAndParentInputPorts.
public void startProcessGroupAndParentInputPorts(ProcessGroupDTO entity) {
// 1 startAll
try {
startAll(entity.getId(), entity.getParentGroupId());
} catch (NifiClientRuntimeException e) {
log.error("Error trying to mark connection ports Running for {}", entity.getName());
}
Set<PortDTO> ports = null;
try {
ports = getPortsForProcessGroup(entity.getParentGroupId());
} catch (NifiClientRuntimeException e) {
log.error("Error getPortsForProcessGroup {}", entity.getName());
}
if (ports != null && !ports.isEmpty()) {
Map<String, PortDTO> portsById = ports.stream().collect(Collectors.toMap(port -> port.getId(), port -> port));
ProcessGroupFlowDTO flow = getNiFiRestClient().processGroups().flow(entity.getParentGroupId());
if (flow != null) {
Set<PortDTO> matchingPorts = new HashSet<>();
flow.getFlow().getConnections().stream().map(connectionEntity -> connectionEntity.getComponent()).forEach(connectionDTO -> {
// map input ports
if (connectionDTO.getDestination().getGroupId().equalsIgnoreCase(entity.getId()) && portsById.containsKey(connectionDTO.getSource().getId())) {
matchingPorts.add(portsById.get(connectionDTO.getSource().getId()));
}
// map output ports
if (connectionDTO.getSource().getGroupId().equalsIgnoreCase(entity.getId()) && portsById.containsKey(connectionDTO.getDestination().getId())) {
matchingPorts.add(portsById.get(connectionDTO.getDestination().getId()));
}
});
for (PortDTO port : matchingPorts) {
port.setState(NifiProcessUtil.PROCESS_STATE.RUNNING.name());
if (port.getType().equalsIgnoreCase(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name())) {
try {
if (port.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name())) {
PortDTO stoppedPort = stopInputPort(entity.getParentGroupId(), port.getId());
if (stoppedPort.getValidationErrors() != null && !stoppedPort.getValidationErrors().isEmpty()) {
startInputPort(entity.getParentGroupId(), port.getId());
} else {
String validationErrors = stoppedPort.getValidationErrors() != null ? ("Validation Errors: " + stoppedPort.getValidationErrors().stream().collect(Collectors.joining(","))) : "";
log.warn("Unable to start input port [" + port.getId() + "] with name: [" + port.getName() + "] within process group: [" + port.getParentGroupId() + "]. " + validationErrors);
}
} else {
startInputPort(entity.getParentGroupId(), port.getId());
}
} catch (NifiClientRuntimeException e) {
log.error("Error starting Input Port {} for process group {}", port.getName(), entity.getName());
}
} else if (port.getType().equalsIgnoreCase(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name())) {
try {
if (port.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name())) {
PortDTO stoppedPort = stopOutputPort(entity.getParentGroupId(), port.getId());
if (stoppedPort.getValidationErrors() != null && !stoppedPort.getValidationErrors().isEmpty()) {
startOutputPort(entity.getParentGroupId(), port.getId());
} else {
String validationErrors = stoppedPort.getValidationErrors() != null ? ("Validation Errors: " + stoppedPort.getValidationErrors().stream().collect(Collectors.joining(","))) : "";
log.warn("Unable to start output port [" + port.getId() + "] with name: [" + port.getName() + "] within process group: [" + port.getParentGroupId() + "]. " + validationErrors);
}
} else {
startOutputPort(entity.getParentGroupId(), port.getId());
}
} catch (NifiClientRuntimeException e) {
log.error("Error starting Output Port {} for process group {}", port.getName(), entity.getName());
}
}
}
}
}
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class LegacyNifiRestClient method getInputProcessors.
/**
* return the Source Processors for a given group
*/
public List<ProcessorDTO> getInputProcessors(String processGroupId) throws NifiComponentNotFoundException {
// get the group
ProcessGroupDTO processGroupEntity = getProcessGroup(processGroupId, false, true);
// get the Source Processors
List<String> sourceIds = getInputProcessorIds(processGroupId);
return NifiProcessUtil.findProcessorsByIds(processGroupEntity.getContents().getProcessors(), sourceIds);
}
Aggregations