use of org.apache.nifi.connectable.Port in project nifi by apache.
the class PortAuditor method createPortAdvice.
/**
* Audits the creation of a port.
*
* @param proceedingJoinPoint join point
* @return port
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.PortDAO+) && " + "execution(org.apache.nifi.connectable.Port createPort(java.lang.String, org.apache.nifi.web.api.dto.PortDTO))")
public Port createPortAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
// perform the underlying operation
Port port = (Port) proceedingJoinPoint.proceed();
// audit the port creation
final Action action = generateAuditRecord(port, Operation.Add);
// save the actions
if (action != null) {
saveAction(action, logger);
}
return port;
}
use of org.apache.nifi.connectable.Port in project nifi by apache.
the class RelationshipAuditor method determineConnectableType.
/**
* Determines the type of component the specified connectable is.
*/
private Component determineConnectableType(Connectable connectable) {
String sourceId = connectable.getIdentifier();
Component componentType = Component.Controller;
if (connectable instanceof ProcessorNode) {
componentType = Component.Processor;
} else if (connectable instanceof RemoteGroupPort) {
final RemoteGroupPort remoteGroupPort = (RemoteGroupPort) connectable;
if (TransferDirection.RECEIVE.equals(remoteGroupPort.getTransferDirection())) {
if (remoteGroupPort.getRemoteProcessGroup() == null) {
componentType = Component.InputPort;
} else {
componentType = Component.OutputPort;
}
} else {
if (remoteGroupPort.getRemoteProcessGroup() == null) {
componentType = Component.OutputPort;
} else {
componentType = Component.InputPort;
}
}
} else if (connectable instanceof Port) {
ProcessGroup processGroup = connectable.getProcessGroup();
if (processGroup.getInputPort(sourceId) != null) {
componentType = Component.InputPort;
} else if (processGroup.getOutputPort(sourceId) != null) {
componentType = Component.OutputPort;
}
} else if (connectable instanceof Funnel) {
componentType = Component.Funnel;
}
return componentType;
}
use of org.apache.nifi.connectable.Port in project nifi by apache.
the class SnippetAuditor method updateSnippetAdvice.
/**
* Audits a bulk move.
*
* @param proceedingJoinPoint join point
* @param snippetDTO dto
* @param snippetDAO dao
* @return snippet
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.SnippetDAO+) && " + "execution(org.apache.nifi.controller.Snippet updateSnippetComponents(org.apache.nifi.web.api.dto.SnippetDTO)) && " + "args(snippetDTO) && " + "target(snippetDAO)")
public Snippet updateSnippetAdvice(ProceedingJoinPoint proceedingJoinPoint, SnippetDTO snippetDTO, SnippetDAO snippetDAO) throws Throwable {
// get the snippet before removing it
Snippet snippet = snippetDAO.getSnippet(snippetDTO.getId());
final String previousGroupId = snippet.getParentGroupId();
// perform the underlying operation
snippet = (Snippet) proceedingJoinPoint.proceed();
// if this snippet is linked and its parent group id has changed
final String groupId = snippetDTO.getParentGroupId();
if (!previousGroupId.equals(groupId)) {
// create move audit records for all items in this snippet
final Collection<Action> actions = new ArrayList<>();
for (String id : snippet.getProcessors().keySet()) {
final ProcessorNode processor = processorDAO.getProcessor(id);
final Action action = processorAuditor.generateAuditRecord(processor, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getFunnels().keySet()) {
final Funnel funnel = funnelDAO.getFunnel(id);
final Action action = funnelAuditor.generateAuditRecord(funnel, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getInputPorts().keySet()) {
final Port port = inputPortDAO.getPort(id);
final Action action = portAuditor.generateAuditRecord(port, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getOutputPorts().keySet()) {
final Port port = outputPortDAO.getPort(id);
final Action action = portAuditor.generateAuditRecord(port, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getRemoteProcessGroups().keySet()) {
final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(id);
final Action action = remoteProcessGroupAuditor.generateAuditRecord(remoteProcessGroup, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getProcessGroups().keySet()) {
final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
final ProcessGroup processGroup = processGroupDAO.getProcessGroup(id);
final Action action = processGroupAuditor.generateAuditRecord(processGroup, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getConnections().keySet()) {
final Connection connection = connectionDAO.getConnection(id);
final Action action = relationshipAuditor.generateAuditRecordForConnection(connection, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
// save the actions
if (CollectionUtils.isNotEmpty(actions)) {
saveActions(actions, logger);
}
}
return snippet;
}
use of org.apache.nifi.connectable.Port in project nifi by apache.
the class StandardAuthorizableLookup method getRootGroupInputPort.
@Override
public RootGroupPortAuthorizable getRootGroupInputPort(String id) {
final Port inputPort = inputPortDAO.getPort(id);
if (!(inputPort instanceof RootGroupPort)) {
throw new IllegalArgumentException(String.format("The specified id '%s' does not represent an input port in the root group.", id));
}
final DataTransferAuthorizable baseAuthorizable = new DataTransferAuthorizable(inputPort);
return new RootGroupPortAuthorizable() {
@Override
public Authorizable getAuthorizable() {
return baseAuthorizable;
}
@Override
public AuthorizationResult checkAuthorization(NiFiUser user) {
// perform the authorization of the user by using the underlying component, ensures consistent authorization with raw s2s
final PortAuthorizationResult authorizationResult = ((RootGroupPort) inputPort).checkUserAuthorization(user);
if (authorizationResult.isAuthorized()) {
return AuthorizationResult.approved();
} else {
return AuthorizationResult.denied(authorizationResult.getExplanation());
}
}
};
}
use of org.apache.nifi.connectable.Port in project nifi by apache.
the class SnippetUtils method resolveNameConflicts.
private void resolveNameConflicts(final FlowSnippetDTO snippetContents, final ProcessGroup group) {
// get a list of all names of ports so that we can rename the ports as needed.
final List<String> existingPortNames = new ArrayList<>();
for (final Port inputPort : group.getInputPorts()) {
existingPortNames.add(inputPort.getName());
}
for (final Port outputPort : group.getOutputPorts()) {
existingPortNames.add(outputPort.getName());
}
// rename ports
if (snippetContents.getInputPorts() != null) {
for (final PortDTO portDTO : snippetContents.getInputPorts()) {
String portName = portDTO.getName();
while (existingPortNames.contains(portName)) {
portName = "Copy of " + portName;
}
portDTO.setName(portName);
existingPortNames.add(portDTO.getName());
}
}
if (snippetContents.getOutputPorts() != null) {
for (final PortDTO portDTO : snippetContents.getOutputPorts()) {
String portName = portDTO.getName();
while (existingPortNames.contains(portName)) {
portName = "Copy of " + portName;
}
portDTO.setName(portName);
existingPortNames.add(portDTO.getName());
}
}
// get a list of all names of process groups so that we can rename as needed.
final Set<String> groupNames = new HashSet<>();
for (final ProcessGroup childGroup : group.getProcessGroups()) {
groupNames.add(childGroup.getName());
}
if (snippetContents.getProcessGroups() != null) {
for (final ProcessGroupDTO groupDTO : snippetContents.getProcessGroups()) {
// 'Copy of...' so we do this only if there is no Version Control Information present.
if (groupDTO.getVersionControlInformation() == null) {
String groupName = groupDTO.getName();
while (groupNames.contains(groupName)) {
groupName = "Copy of " + groupName;
}
groupDTO.setName(groupName);
}
groupNames.add(groupDTO.getName());
}
}
}
Aggregations