mirror of https://github.com/apache/nifi.git
NIFI-1513: fixed some easy to fix errors
Addressing checkstyle issue. This closes #221 Signed-off-by: Matt Gilman <matt.c.gilman@gmail.com>
This commit is contained in:
parent
32f476aaa7
commit
c7e24c7569
|
@ -44,7 +44,7 @@ public final class Relationship implements Comparable<Relationship> {
|
|||
protected Relationship(final Builder builder) {
|
||||
this.name = builder.name == null ? null : builder.name.intern();
|
||||
this.description = builder.description;
|
||||
this.hashCode = 301 + this.name.hashCode(); // compute only once, since it gets called a bunch and will never change
|
||||
this.hashCode = 301 + ( (name == null) ? 0 :this.name.hashCode() ); // compute only once, since it gets called a bunch and will never change
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -99,7 +99,7 @@ public class GetDelimitedFieldEvaluator extends StringEvaluator {
|
|||
if (escapeString == null || escapeString.isEmpty()) {
|
||||
throw new AttributeExpressionLanguageException("Cannot evaluate getDelimitedField function because the escape character "
|
||||
+ "(which character is used to escape the quote character or delimiter) was not specified");
|
||||
} else if (quoteString.length() > 1) {
|
||||
} else if (escapeString.length() > 1) {
|
||||
throw new AttributeExpressionLanguageException("Cannot evaluate getDelimitedField function because the escape character "
|
||||
+ "(which character is used to escape the quote character or delimiter) evaluated to \"" + escapeString + "\", but only a single character is allowed.");
|
||||
}
|
||||
|
|
|
@ -25,6 +25,10 @@ import org.apache.nifi.flowfile.FlowFile;
|
|||
import org.apache.nifi.processor.ProcessSession;
|
||||
import org.apache.nifi.processor.util.FlowFileSessionWrapper;
|
||||
|
||||
/**
|
||||
* Note: {@code Bin} objects are NOT thread safe. If multiple threads access a {@code Bin}, the caller must synchronize
|
||||
* access.
|
||||
*/
|
||||
public class Bin {
|
||||
|
||||
private final long creationMomentEpochNs;
|
||||
|
@ -121,8 +125,9 @@ public class Bin {
|
|||
final String countValue = flowFile.getAttribute(fileCountAttribute);
|
||||
final Integer count = toInteger(countValue);
|
||||
if (count != null) {
|
||||
this.maximumEntries = Math.min(count, this.maximumEntries);
|
||||
this.minimumEntries = this.maximumEntries;
|
||||
int currentMaxEntries = this.maximumEntries;
|
||||
this.maximumEntries = Math.min(count, currentMaxEntries);
|
||||
this.minimumEntries = currentMaxEntries;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -610,7 +610,7 @@ public interface SiteToSiteClient extends Closeable {
|
|||
trustManagerFactory = null;
|
||||
}
|
||||
|
||||
if (keyManagerFactory != null || trustManagerFactory != null) {
|
||||
if (keyManagerFactory != null && trustManagerFactory != null) {
|
||||
try {
|
||||
// initialize the ssl context
|
||||
final SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
|
|
|
@ -3015,8 +3015,9 @@ public class WebClusterManager implements HttpClusterManager, ProtocolHandler, C
|
|||
|
||||
final List<FlowFileSummaryDTO> summaryDTOs = new ArrayList<>(flowFileSummaries);
|
||||
listingRequest.setFlowFileSummaries(summaryDTOs);
|
||||
|
||||
final int percentCompleted = numStepsCompleted / numStepsTotal;
|
||||
// depends on invariant if numStepsTotal is 0, so is numStepsCompleted, all steps being completed
|
||||
// would be 1
|
||||
final int percentCompleted = (numStepsTotal == 0) ? 1 : numStepsCompleted / numStepsTotal;
|
||||
listingRequest.setPercentCompleted(percentCompleted);
|
||||
listingRequest.setFinished(finished);
|
||||
|
||||
|
|
|
@ -133,7 +133,9 @@ public class ExecuteScript extends AbstractScriptProcessor {
|
|||
|
||||
try {
|
||||
if (scriptToRun == null && scriptPath != null) {
|
||||
scriptToRun = IOUtils.toString(new FileInputStream(scriptPath));
|
||||
try (final FileInputStream scriptStream = new FileInputStream(scriptPath)) {
|
||||
scriptToRun = IOUtils.toString(scriptStream);
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
throw new ProcessException(ioe);
|
||||
|
|
|
@ -398,9 +398,6 @@ public class GetHTTP extends AbstractSessionFactoryProcessor {
|
|||
clientBuilder.setProxy(new HttpHost(host, port));
|
||||
}
|
||||
|
||||
// create the http client
|
||||
final CloseableHttpClient client = clientBuilder.build();
|
||||
|
||||
// create request
|
||||
final HttpGet get = new HttpGet(url);
|
||||
get.setConfig(requestConfigBuilder.build());
|
||||
|
@ -426,60 +423,65 @@ public class GetHTTP extends AbstractSessionFactoryProcessor {
|
|||
if (accept != null) {
|
||||
get.addHeader(HEADER_ACCEPT, accept);
|
||||
}
|
||||
|
||||
try {
|
||||
final StopWatch stopWatch = new StopWatch(true);
|
||||
final HttpResponse response = client.execute(get);
|
||||
final int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode == NOT_MODIFIED) {
|
||||
logger.info("content not retrieved because server returned HTTP Status Code {}: Not Modified", new Object[]{NOT_MODIFIED});
|
||||
context.yield();
|
||||
// doing a commit in case there were flow files in the input queue
|
||||
session.commit();
|
||||
return;
|
||||
}
|
||||
final String statusExplanation = response.getStatusLine().getReasonPhrase();
|
||||
|
||||
if (statusCode >= 300) {
|
||||
logger.error("received status code {}:{} from {}", new Object[]{statusCode, statusExplanation, url});
|
||||
// doing a commit in case there were flow files in the input queue
|
||||
session.commit();
|
||||
return;
|
||||
}
|
||||
|
||||
FlowFile flowFile = session.create();
|
||||
flowFile = session.putAttribute(flowFile, CoreAttributes.FILENAME.key(), context.getProperty(FILENAME).evaluateAttributeExpressions().getValue());
|
||||
flowFile = session.putAttribute(flowFile, this.getClass().getSimpleName().toLowerCase() + ".remote.source", source);
|
||||
flowFile = session.importFrom(response.getEntity().getContent(), flowFile);
|
||||
|
||||
final Header contentTypeHeader = response.getFirstHeader("Content-Type");
|
||||
if (contentTypeHeader != null) {
|
||||
final String contentType = contentTypeHeader.getValue();
|
||||
if (!contentType.trim().isEmpty()) {
|
||||
flowFile = session.putAttribute(flowFile, CoreAttributes.MIME_TYPE.key(), contentType.trim());
|
||||
// create the http client
|
||||
try ( final CloseableHttpClient client = clientBuilder.build() ) {
|
||||
// NOTE: including this inner try in order to swallow exceptions on close
|
||||
try {
|
||||
final StopWatch stopWatch = new StopWatch(true);
|
||||
final HttpResponse response = client.execute(get);
|
||||
final int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode == NOT_MODIFIED) {
|
||||
logger.info("content not retrieved because server returned HTTP Status Code {}: Not Modified", new Object[]{NOT_MODIFIED});
|
||||
context.yield();
|
||||
// doing a commit in case there were flow files in the input queue
|
||||
session.commit();
|
||||
return;
|
||||
}
|
||||
final String statusExplanation = response.getStatusLine().getReasonPhrase();
|
||||
|
||||
if (statusCode >= 300) {
|
||||
logger.error("received status code {}:{} from {}", new Object[]{statusCode, statusExplanation, url});
|
||||
// doing a commit in case there were flow files in the input queue
|
||||
session.commit();
|
||||
return;
|
||||
}
|
||||
|
||||
FlowFile flowFile = session.create();
|
||||
flowFile = session.putAttribute(flowFile, CoreAttributes.FILENAME.key(), context.getProperty(FILENAME).evaluateAttributeExpressions().getValue());
|
||||
flowFile = session.putAttribute(flowFile, this.getClass().getSimpleName().toLowerCase() + ".remote.source", source);
|
||||
flowFile = session.importFrom(response.getEntity().getContent(), flowFile);
|
||||
|
||||
final Header contentTypeHeader = response.getFirstHeader("Content-Type");
|
||||
if (contentTypeHeader != null) {
|
||||
final String contentType = contentTypeHeader.getValue();
|
||||
if (!contentType.trim().isEmpty()) {
|
||||
flowFile = session.putAttribute(flowFile, CoreAttributes.MIME_TYPE.key(), contentType.trim());
|
||||
}
|
||||
}
|
||||
|
||||
final long flowFileSize = flowFile.getSize();
|
||||
stopWatch.stop();
|
||||
final String dataRate = stopWatch.calculateDataRate(flowFileSize);
|
||||
session.getProvenanceReporter().receive(flowFile, url, stopWatch.getDuration(TimeUnit.MILLISECONDS));
|
||||
session.transfer(flowFile, REL_SUCCESS);
|
||||
logger.info("Successfully received {} from {} at a rate of {}; transferred to success", new Object[]{flowFile, url, dataRate});
|
||||
session.commit();
|
||||
|
||||
updateStateMap(context,response,beforeStateMap,url);
|
||||
|
||||
} catch (final IOException e) {
|
||||
context.yield();
|
||||
session.rollback();
|
||||
logger.error("Failed to retrieve file from {} due to {}; rolling back session", new Object[]{url, e.getMessage()}, e);
|
||||
throw new ProcessException(e);
|
||||
} catch (final Throwable t) {
|
||||
context.yield();
|
||||
session.rollback();
|
||||
logger.error("Failed to process due to {}; rolling back session", new Object[]{t.getMessage()}, t);
|
||||
throw t;
|
||||
}
|
||||
|
||||
final long flowFileSize = flowFile.getSize();
|
||||
stopWatch.stop();
|
||||
final String dataRate = stopWatch.calculateDataRate(flowFileSize);
|
||||
session.getProvenanceReporter().receive(flowFile, url, stopWatch.getDuration(TimeUnit.MILLISECONDS));
|
||||
session.transfer(flowFile, REL_SUCCESS);
|
||||
logger.info("Successfully received {} from {} at a rate of {}; transferred to success", new Object[]{flowFile, url, dataRate});
|
||||
session.commit();
|
||||
|
||||
updateStateMap(context,response,beforeStateMap,url);
|
||||
|
||||
} catch (final IOException e) {
|
||||
context.yield();
|
||||
session.rollback();
|
||||
logger.error("Failed to retrieve file from {} due to {}; rolling back session", new Object[]{url, e.getMessage()}, e);
|
||||
throw new ProcessException(e);
|
||||
} catch (final Throwable t) {
|
||||
context.yield();
|
||||
session.rollback();
|
||||
logger.error("Failed to process due to {}; rolling back session", new Object[]{t.getMessage()}, t);
|
||||
throw t;
|
||||
logger.debug("Error closing client due to {}, continuing.", new Object[]{e.getMessage()});
|
||||
}
|
||||
} finally {
|
||||
conMan.shutdown();
|
||||
|
|
|
@ -25,6 +25,8 @@ import org.apache.nifi.flowfile.FlowFile;
|
|||
import org.apache.nifi.processor.ProcessSession;
|
||||
|
||||
/**
|
||||
* Note: {@code Bin} objects are NOT thread safe. If multiple threads access a {@code Bin}, the caller must synchronize
|
||||
* access.
|
||||
* @deprecated As of release 0.5.0, replaced by
|
||||
* {@link org.apache.nifi.processor.util.bin.Bin}
|
||||
*/
|
||||
|
@ -125,8 +127,9 @@ public class Bin {
|
|||
final String countValue = flowFile.getAttribute(fileCountAttribute);
|
||||
final Integer count = toInteger(countValue);
|
||||
if (count != null) {
|
||||
this.maximumEntries = Math.min(count, this.maximumEntries);
|
||||
this.minimumEntries = this.maximumEntries;
|
||||
final int currentMaximumEntries = this.maximumEntries;
|
||||
this.maximumEntries = Math.min(count, currentMaximumEntries);
|
||||
this.minimumEntries = currentMaximumEntries;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -285,6 +285,8 @@ public class Scrypt {
|
|||
// Do not enforce this check here. According to the scrypt spec, the salt can be empty. However, in the user-facing ScryptCipherProvider, enforce an arbitrary check to avoid empty salts
|
||||
logger.warn("An empty salt was used for scrypt key derivation");
|
||||
// throw new IllegalArgumentException("Salt cannot be empty");
|
||||
// as the Exception is not being thrown, prevent NPE if salt is null by setting it to empty array
|
||||
if( salt == null ) salt = new byte[]{};
|
||||
}
|
||||
|
||||
if (saltLength < 8 || saltLength > 32) {
|
||||
|
|
|
@ -105,7 +105,6 @@ public class ControllerStatusReportingTask extends AbstractReportingTask {
|
|||
@Override
|
||||
public void onTrigger(final ReportingContext context) {
|
||||
final ProcessGroupStatus controllerStatus = context.getEventAccess().getControllerStatus();
|
||||
controllerStatus.clone();
|
||||
|
||||
final boolean showDeltas = context.getProperty(SHOW_DELTAS).asBoolean();
|
||||
|
||||
|
|
|
@ -117,8 +117,7 @@ public class StandardGangliaReporter extends AbstractReportingTask {
|
|||
return 0L;
|
||||
}
|
||||
|
||||
final Long value = status.getBytesReceived();
|
||||
return (value == null) ? 0L : value;
|
||||
return status.getBytesReceived();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -130,8 +129,7 @@ public class StandardGangliaReporter extends AbstractReportingTask {
|
|||
return 0;
|
||||
}
|
||||
|
||||
final Integer value = status.getFlowFilesSent();
|
||||
return (value == null) ? 0 : value;
|
||||
return status.getFlowFilesSent();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -142,9 +140,7 @@ public class StandardGangliaReporter extends AbstractReportingTask {
|
|||
if (status == null) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
final Long value = status.getBytesSent();
|
||||
return (value == null) ? 0L : value;
|
||||
return status.getBytesSent();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue