use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.
the class StandardInputPortDAO method updatePort.
@Override
public Port updatePort(PortDTO portDTO) {
Port inputPort = locatePort(portDTO.getId());
// ensure we can do this update
verifyUpdate(inputPort, portDTO);
// handle state transition
if (isNotNull(portDTO.getState())) {
final ScheduledState purposedScheduledState = ScheduledState.valueOf(portDTO.getState());
// only attempt an action if it is changing
if (!purposedScheduledState.equals(inputPort.getScheduledState())) {
try {
// perform the appropriate action
switch(purposedScheduledState) {
case RUNNING:
inputPort.getProcessGroup().startInputPort(inputPort);
break;
case STOPPED:
switch(inputPort.getScheduledState()) {
case RUNNING:
inputPort.getProcessGroup().stopInputPort(inputPort);
break;
case DISABLED:
inputPort.getProcessGroup().enableInputPort(inputPort);
break;
}
break;
case DISABLED:
inputPort.getProcessGroup().disableInputPort(inputPort);
break;
}
} catch (IllegalStateException ise) {
throw new NiFiCoreException(ise.getMessage(), ise);
}
}
}
if (inputPort instanceof RootGroupPort) {
final RootGroupPort rootPort = (RootGroupPort) inputPort;
if (isNotNull(portDTO.getGroupAccessControl())) {
rootPort.setGroupAccessControl(portDTO.getGroupAccessControl());
}
if (isNotNull(portDTO.getUserAccessControl())) {
rootPort.setUserAccessControl(portDTO.getUserAccessControl());
}
}
// update the port
final String name = portDTO.getName();
final String comments = portDTO.getComments();
final Integer concurrentTasks = portDTO.getConcurrentlySchedulableTaskCount();
if (isNotNull(portDTO.getPosition())) {
inputPort.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
}
if (isNotNull(name)) {
inputPort.setName(name);
}
if (isNotNull(comments)) {
inputPort.setComments(comments);
}
if (isNotNull(concurrentTasks)) {
inputPort.setMaxConcurrentTasks(concurrentTasks);
}
inputPort.getProcessGroup().onComponentModified();
return inputPort;
}
use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.
the class StandardOutputPortDAO method updatePort.
@Override
public Port updatePort(PortDTO portDTO) {
Port outputPort = locatePort(portDTO.getId());
// ensure we can do this update
verifyUpdate(outputPort, portDTO);
// handle state transition
if (portDTO.getState() != null) {
final ScheduledState purposedScheduledState = ScheduledState.valueOf(portDTO.getState());
// only attempt an action if it is changing
if (!purposedScheduledState.equals(outputPort.getScheduledState())) {
try {
// perform the appropriate action
switch(purposedScheduledState) {
case RUNNING:
outputPort.getProcessGroup().startOutputPort(outputPort);
break;
case STOPPED:
switch(outputPort.getScheduledState()) {
case RUNNING:
outputPort.getProcessGroup().stopOutputPort(outputPort);
break;
case DISABLED:
outputPort.getProcessGroup().enableOutputPort(outputPort);
break;
}
break;
case DISABLED:
outputPort.getProcessGroup().disableOutputPort(outputPort);
break;
}
} catch (IllegalStateException ise) {
throw new NiFiCoreException(ise.getMessage(), ise);
}
}
}
if (outputPort instanceof RootGroupPort) {
final RootGroupPort rootPort = (RootGroupPort) outputPort;
if (isNotNull(portDTO.getGroupAccessControl())) {
rootPort.setGroupAccessControl(portDTO.getGroupAccessControl());
}
if (isNotNull(portDTO.getUserAccessControl())) {
rootPort.setUserAccessControl(portDTO.getUserAccessControl());
}
}
// perform the configuration
final String name = portDTO.getName();
final String comments = portDTO.getComments();
final Integer concurrentTasks = portDTO.getConcurrentlySchedulableTaskCount();
if (isNotNull(portDTO.getPosition())) {
outputPort.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
}
if (isNotNull(name)) {
outputPort.setName(name);
}
if (isNotNull(comments)) {
outputPort.setComments(comments);
}
if (isNotNull(concurrentTasks)) {
outputPort.setMaxConcurrentTasks(concurrentTasks);
}
outputPort.getProcessGroup().onComponentModified();
return outputPort;
}
use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.
the class StandardProcessorDAO method updateProcessor.
@Override
public ProcessorNode updateProcessor(ProcessorDTO processorDTO) {
ProcessorNode processor = locateProcessor(processorDTO.getId());
ProcessGroup parentGroup = processor.getProcessGroup();
// ensure we can perform the update
verifyUpdate(processor, processorDTO);
// configure the processor
configureProcessor(processor, processorDTO);
parentGroup.onComponentModified();
// attempt to change the underlying processor if an updated bundle is specified
// updating the bundle must happen after configuring so that any additional classpath resources are set first
updateBundle(processor, processorDTO);
// see if an update is necessary
if (isNotNull(processorDTO.getState())) {
final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());
// only attempt an action if it is changing
if (!purposedScheduledState.equals(processor.getScheduledState())) {
try {
// perform the appropriate action
switch(purposedScheduledState) {
case RUNNING:
parentGroup.startProcessor(processor, true);
break;
case STOPPED:
switch(processor.getScheduledState()) {
case RUNNING:
parentGroup.stopProcessor(processor);
break;
case DISABLED:
parentGroup.enableProcessor(processor);
break;
}
break;
case DISABLED:
parentGroup.disableProcessor(processor);
break;
}
} catch (IllegalStateException | ComponentLifeCycleException ise) {
throw new NiFiCoreException(ise.getMessage(), ise);
} catch (RejectedExecutionException ree) {
throw new NiFiCoreException("Unable to schedule all tasks for the specified processor.", ree);
} catch (NullPointerException npe) {
throw new NiFiCoreException("Unable to update processor run state.", npe);
} catch (Exception e) {
throw new NiFiCoreException("Unable to update processor run state: " + e, e);
}
}
}
return processor;
}
use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.
the class StandardReportingTaskDAO method updateBundle.
private void updateBundle(ReportingTaskNode reportingTask, ReportingTaskDTO reportingTaskDTO) {
final BundleDTO bundleDTO = reportingTaskDTO.getBundle();
if (bundleDTO != null) {
final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(reportingTask.getCanonicalClassName(), bundleDTO);
final BundleCoordinate existingCoordinate = reportingTask.getBundleCoordinate();
if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) {
try {
// we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component
final ConfigurableComponent tempComponent = ExtensionManager.getTempComponent(reportingTask.getCanonicalClassName(), incomingCoordinate);
final Set<URL> additionalUrls = reportingTask.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors());
reloadComponent.reload(reportingTask, reportingTask.getCanonicalClassName(), incomingCoordinate, additionalUrls);
} catch (ReportingTaskInstantiationException e) {
throw new NiFiCoreException(String.format("Unable to update reporting task %s from %s to %s due to: %s", reportingTaskDTO.getId(), reportingTask.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e);
}
}
}
}
use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.
the class StandardSnippetDAO method copySnippet.
@Override
public FlowSnippetDTO copySnippet(final String groupId, final String snippetId, final Double originX, final Double originY, final String idGenerationSeed) {
try {
// ensure the parent group exist
final ProcessGroup processGroup = flowController.getGroup(groupId);
if (processGroup == null) {
throw new IllegalArgumentException("The specified parent process group could not be found");
}
// get the existing snippet
Snippet existingSnippet = getSnippet(snippetId);
// get the process group
ProcessGroup existingSnippetProcessGroup = flowController.getGroup(existingSnippet.getParentGroupId());
// ensure the group could be found
if (existingSnippetProcessGroup == null) {
throw new IllegalStateException("The parent process group for the existing snippet could not be found.");
}
// generate the snippet contents
FlowSnippetDTO snippetContents = snippetUtils.populateFlowSnippet(existingSnippet, true, false, false);
// resolve sensitive properties
lookupSensitiveProperties(snippetContents);
// copy snippet
snippetContents = snippetUtils.copy(snippetContents, processGroup, idGenerationSeed, true);
// move the snippet if necessary
if (originX != null && originY != null) {
org.apache.nifi.util.SnippetUtils.moveSnippet(snippetContents, originX, originY);
}
try {
// instantiate the snippet and return the contents
flowController.instantiateSnippet(processGroup, snippetContents);
return snippetContents;
} catch (IllegalStateException ise) {
// illegal state will be thrown from instantiateSnippet when there is an issue with the snippet _before_ any of the
// components are actually created. if we've received this exception we want to attempt to roll back any of the
// policies that we've already cloned for this request
snippetUtils.rollbackClonedPolicies(snippetContents);
// rethrow the same exception
throw ise;
}
} catch (ProcessorInstantiationException pie) {
throw new NiFiCoreException(String.format("Unable to copy snippet because processor type '%s' is unknown to this NiFi.", StringUtils.substringAfterLast(pie.getMessage(), ".")));
}
}
Aggregations