if (port.isRunning()) { throw new IllegalStateException(this.getIdentifier() + " has running Port: " + port.getIdentifier()); if (port.hasIncomingConnection() && !port.getTargetExists()) { throw new IllegalStateException(this.getIdentifier() + " has a Connection to Port " + port.getIdentifier() + ", but that Port no longer exists on the remote system"); if (port.hasIncomingConnection()) { port.verifyCanStart(); if (port.isRunning()) { throw new IllegalStateException(this.getIdentifier() + " has running Port: " + port.getIdentifier()); if (!port.getConnections().isEmpty() && !port.getTargetExists()) { throw new IllegalStateException(this.getIdentifier() + " has a Connection to Port " + port.getIdentifier() + ", but that Port no longer exists on the remote system"); if (!port.getConnections().isEmpty()) { port.verifyCanStart();
sendPort = addInputPort(descriptor); } else { sendPort.setTargetIdentifier(descriptor.getTargetId()); sendPort.setTargetExists(true); sendPort.setName(descriptor.getName()); if (descriptor.isTargetRunning() != null) { sendPort.setTargetRunning(descriptor.isTargetRunning()); sendPort.setComments(descriptor.getComments()); while (itr.hasNext()) { final StandardRemoteGroupPort port = itr.next(); if (!newPortTargetIds.contains(port.getTargetIdentifier())) { port.setTargetExists(false); port.setTargetRunning(false); if (!port.hasIncomingConnection()) { itr.remove();
@Override public Collection<ValidationResult> getValidationErrors() { final Collection<ValidationResult> validationErrors = new ArrayList<>(); if (getScheduledState() == ScheduledState.STOPPED) { ValidationResult error = null; if (!targetExists.get()) { error = new ValidationResult.Builder() .explanation(String.format("Remote instance indicates that port '%s' no longer exists.", getName())) .subject(String.format("Remote port '%s'", getName())) .valid(false) .build(); } else if (getConnectableType() == ConnectableType.REMOTE_OUTPUT_PORT && getConnections(Relationship.ANONYMOUS).isEmpty()) { error = new ValidationResult.Builder() .explanation(String.format("Port '%s' has no outbound connections", getName())) .subject(String.format("Remote port '%s'", getName())) .valid(false) .build(); } if (error != null) { validationErrors.add(error); } } return validationErrors; }
@Override public void removeConnection(final Connection connection) throws IllegalArgumentException, IllegalStateException { super.removeConnection(connection); // If the Port no longer exists on the remote instance and this is the last Connection, tell // RemoteProcessGroup to remove me if (!getTargetExists() && !hasIncomingConnection() && getConnections().isEmpty()) { remoteGroup.removeNonExistentPort(this); } }
@Override public Resource getResource() { final ResourceType resourceType = ConnectableType.REMOTE_INPUT_PORT.equals(getConnectableType()) ? ResourceType.InputPort : ResourceType.OutputPort; return ResourceFactory.getComponentResource(resourceType, getIdentifier(), getName()); }
@Override public boolean isValid() { if (!targetExists.get()) { return false; } if (getConnectableType() == ConnectableType.REMOTE_OUTPUT_PORT && getConnections(Relationship.ANONYMOUS).isEmpty()) { // if it's an output port, ensure that there is an outbound connection return false; } final boolean groupValid = remoteGroup.validate().stream() .allMatch(result -> result.isValid()); return groupValid; }
@Override public void onSchedulingStart() { super.onSchedulingStart(); final long penalizationMillis = FormatUtils.getTimeDuration(remoteGroup.getYieldDuration(), TimeUnit.MILLISECONDS); final SiteToSiteClient.Builder clientBuilder = new SiteToSiteClient.Builder() .urls(SiteToSiteRestApiClient.parseClusterUrls(remoteGroup.getTargetUris())) .portIdentifier(getTargetIdentifier()) .sslContext(sslContext) .useCompression(isUseCompression()) .eventReporter(remoteGroup.getEventReporter()) .peerPersistenceFile(getPeerPersistenceFile(getIdentifier(), nifiProperties, remoteGroup.getTransportProtocol())) .nodePenalizationPeriod(penalizationMillis, TimeUnit.MILLISECONDS) .timeout(remoteGroup.getCommunicationsTimeout(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS) .transportProtocol(remoteGroup.getTransportProtocol()) .httpProxy(new HttpProxy(remoteGroup.getProxyHost(), remoteGroup.getProxyPort(), remoteGroup.getProxyUser(), remoteGroup.getProxyPassword())) .localAddress(remoteGroup.getLocalAddress()); final Integer batchCount = getBatchCount(); if (batchCount != null) { clientBuilder.requestBatchCount(batchCount); } final String batchSize = getBatchSize(); if (batchSize != null && batchSize.length() > 0) { clientBuilder.requestBatchSize(DataUnit.parseDataSize(batchSize.trim(), DataUnit.B).intValue()); } final String batchDuration = getBatchDuration(); if (batchDuration != null && batchDuration.length() > 0) { clientBuilder.requestBatchDuration(FormatUtils.getTimeDuration(batchDuration.trim(), TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS); } clientRef.set(clientBuilder.build()); }
receivePort = addOutputPort(descriptor); } else { receivePort.setTargetIdentifier(descriptor.getTargetId()); receivePort.setTargetExists(true); receivePort.setName(descriptor.getName()); if (descriptor.isTargetRunning() != null) { receivePort.setTargetRunning(descriptor.isTargetRunning()); receivePort.setComments(descriptor.getComments()); while (itr.hasNext()) { final StandardRemoteGroupPort port = itr.next(); if (!newPortTargetIds.contains(port.getTargetIdentifier())) { port.setTargetExists(false); port.setTargetRunning(false); if (port.getConnections().isEmpty()) { itr.remove();
final StandardRemoteGroupPort port = new StandardRemoteGroupPort(descriptor.getId(), descriptor.getTargetId(), descriptor.getName(), getProcessGroup(), this, TransferDirection.RECEIVE, ConnectableType.REMOTE_OUTPUT_PORT, sslContext, scheduler, nifiProperties); outputPorts.put(descriptor.getId(), port); port.setMaxConcurrentTasks(descriptor.getConcurrentlySchedulableTaskCount()); port.setUseCompression(descriptor.getUseCompression()); port.setBatchCount(descriptor.getBatchCount()); port.setBatchSize(descriptor.getBatchSize()); port.setBatchDuration(descriptor.getBatchDuration()); port.setVersionedComponentId(descriptor.getVersionedComponentId());
if (getConnectableType() == ConnectableType.REMOTE_INPUT_PORT && session.getQueueSize().getObjectCount() == 0) { logger.debug("{} No data to send", this); return; final String url = getRemoteProcessGroup().getTargetUri(); if (getConnectableType() == ConnectableType.REMOTE_INPUT_PORT) { firstFlowFile = session.get(); if (firstFlowFile == null) { final SiteToSiteClient client = getSiteToSiteClient(); final Transaction transaction; try { if (getConnectableType() == ConnectableType.REMOTE_INPUT_PORT) { transferFlowFiles(transaction, context, session, firstFlowFile); } else { final int numReceived = receiveFlowFiles(transaction, context, session); if (numReceived == 0) { context.yield();
@Override public void verifyCanStart() { super.verifyCanStart(); if (getConnectableType() == ConnectableType.REMOTE_INPUT_PORT && getIncomingConnections().isEmpty()) { throw new IllegalStateException("Port " + getName() + " has no incoming connections"); } final Optional<ValidationResult> resultOption = remoteGroup.validate().stream() .filter(result -> !result.isValid()) .findFirst(); if (resultOption.isPresent()) { throw new IllegalStateException("Remote Process Group is not valid: " + resultOption.get().toString()); } }
long bytesSent = 0L; final SiteToSiteClientConfig siteToSiteClientConfig = getSiteToSiteClient().getConfig(); final long maxBatchBytes = siteToSiteClientConfig.getPreferredBatchSize(); final int maxBatchCount = siteToSiteClientConfig.getPreferredBatchCount(); flowFile = session.putAttribute(flowFile, SiteToSiteAttributes.S2S_PORT_ID.key(), getTargetIdentifier()); session.getProvenanceReporter().send(flowFile, transitUri, "Remote DN=" + userDn, transferMillis, false); session.remove(flowFile);
@Override public String getTargetIdentifier() { final String target = this.targetId; return target == null ? getIdentifier() : target; }
attributes.put(SiteToSiteAttributes.S2S_HOST.key(), host); attributes.put(SiteToSiteAttributes.S2S_ADDRESS.key(), host + ":" + port); attributes.put(SiteToSiteAttributes.S2S_PORT_ID.key(), getTargetIdentifier());
@Override public boolean isTriggerWhenEmpty() { return getConnectableType() == ConnectableType.REMOTE_OUTPUT_PORT; }
@Override public void onSchedulingStart() { super.onSchedulingStart(); final long penalizationMillis = FormatUtils.getTimeDuration(remoteGroup.getYieldDuration(), TimeUnit.MILLISECONDS); final SiteToSiteClient.Builder clientBuilder = new SiteToSiteClient.Builder() .urls(SiteToSiteRestApiClient.parseClusterUrls(remoteGroup.getTargetUris())) .portIdentifier(getTargetIdentifier()) .sslContext(sslContext) .useCompression(isUseCompression()) .eventReporter(remoteGroup.getEventReporter()) .peerPersistenceFile(getPeerPersistenceFile(getIdentifier(), nifiProperties, remoteGroup.getTransportProtocol())) .nodePenalizationPeriod(penalizationMillis, TimeUnit.MILLISECONDS) .timeout(remoteGroup.getCommunicationsTimeout(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS) .transportProtocol(remoteGroup.getTransportProtocol()) .httpProxy(new HttpProxy(remoteGroup.getProxyHost(), remoteGroup.getProxyPort(), remoteGroup.getProxyUser(), remoteGroup.getProxyPassword())) .localAddress(remoteGroup.getLocalAddress()); final Integer batchCount = getBatchCount(); if (batchCount != null) { clientBuilder.requestBatchCount(batchCount); } final String batchSize = getBatchSize(); if (batchSize != null && batchSize.length() > 0) { clientBuilder.requestBatchSize(DataUnit.parseDataSize(batchSize.trim(), DataUnit.B).intValue()); } final String batchDuration = getBatchDuration(); if (batchDuration != null && batchDuration.length() > 0) { clientBuilder.requestBatchDuration(FormatUtils.getTimeDuration(batchDuration.trim(), TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS); } clientRef.set(clientBuilder.build()); }
final StandardRemoteGroupPort port = new StandardRemoteGroupPort(descriptor.getId(), descriptor.getTargetId(), descriptor.getName(), getProcessGroup(), this, TransferDirection.SEND, ConnectableType.REMOTE_INPUT_PORT, sslContext, scheduler, nifiProperties); port.setMaxConcurrentTasks(descriptor.getConcurrentlySchedulableTaskCount()); port.setUseCompression(descriptor.getUseCompression()); port.setBatchCount(descriptor.getBatchCount()); port.setBatchSize(descriptor.getBatchSize()); port.setBatchDuration(descriptor.getBatchDuration()); port.setVersionedComponentId(descriptor.getVersionedComponentId());
@Override public void removeConnection(final Connection connection) throws IllegalArgumentException, IllegalStateException { super.removeConnection(connection); // If the Port no longer exists on the remote instance and this is the last Connection, tell // RemoteProcessGroup to remove me if (!getTargetExists() && !hasIncomingConnection() && getConnections().isEmpty()) { remoteGroup.removeNonExistentPort(this); } }
if (getConnectableType() == ConnectableType.REMOTE_INPUT_PORT && session.getQueueSize().getObjectCount() == 0) { logger.debug("{} No data to send", this); return; final String url = getRemoteProcessGroup().getTargetUri(); if (getConnectableType() == ConnectableType.REMOTE_INPUT_PORT) { firstFlowFile = session.get(); if (firstFlowFile == null) { final SiteToSiteClient client = getSiteToSiteClient(); final Transaction transaction; try { if (getConnectableType() == ConnectableType.REMOTE_INPUT_PORT) { transferFlowFiles(transaction, context, session, firstFlowFile); } else { final int numReceived = receiveFlowFiles(transaction, context, session); if (numReceived == 0) { context.yield();
@Override public Resource getResource() { final ResourceType resourceType = ConnectableType.REMOTE_INPUT_PORT.equals(getConnectableType()) ? ResourceType.InputPort : ResourceType.OutputPort; return ResourceFactory.getComponentResource(resourceType, getIdentifier(), getName()); }