use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.
the class StandardReportingTaskDAO method updateReportingTask.
@Override
public ReportingTaskNode updateReportingTask(final ReportingTaskDTO reportingTaskDTO) {
// get the reporting task
final ReportingTaskNode reportingTask = locateReportingTask(reportingTaskDTO.getId());
// ensure we can perform the update
verifyUpdate(reportingTask, reportingTaskDTO);
// perform the update
configureReportingTask(reportingTask, reportingTaskDTO);
// 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(reportingTask, reportingTaskDTO);
// see if an update is necessary
if (isNotNull(reportingTaskDTO.getState())) {
final ScheduledState purposedScheduledState = ScheduledState.valueOf(reportingTaskDTO.getState());
// only attempt an action if it is changing
if (!purposedScheduledState.equals(reportingTask.getScheduledState())) {
try {
// perform the appropriate action
switch(purposedScheduledState) {
case RUNNING:
reportingTaskProvider.startReportingTask(reportingTask);
break;
case STOPPED:
switch(reportingTask.getScheduledState()) {
case RUNNING:
reportingTaskProvider.stopReportingTask(reportingTask);
break;
case DISABLED:
reportingTaskProvider.enableReportingTask(reportingTask);
break;
}
break;
case DISABLED:
reportingTaskProvider.disableReportingTask(reportingTask);
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 reporting task.", ree);
} catch (NullPointerException npe) {
throw new NiFiCoreException("Unable to update reporting task run state.", npe);
} catch (Exception e) {
throw new NiFiCoreException("Unable to update reporting task run state: " + e, e);
}
}
}
return reportingTask;
}
use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.
the class FlowRegistryUtils method getRestrictedComponents.
public static Set<ConfigurableComponent> getRestrictedComponents(final VersionedProcessGroup group) {
final Set<ConfigurableComponent> restrictedComponents = new HashSet<>();
final Set<Tuple<String, BundleCoordinate>> componentTypes = new HashSet<>();
populateComponentTypes(group, componentTypes);
for (final Tuple<String, BundleCoordinate> tuple : componentTypes) {
final ConfigurableComponent component = ExtensionManager.getTempComponent(tuple.getKey(), tuple.getValue());
if (component == null) {
throw new NiFiCoreException("Could not create an instance of component " + tuple.getKey() + " using bundle coordinates " + tuple.getValue());
}
final boolean isRestricted = component.getClass().isAnnotationPresent(Restricted.class);
if (isRestricted) {
restrictedComponents.add(component);
}
}
return restrictedComponents;
}
use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.
the class StandardTemplateDAO method instantiateTemplate.
@Override
public FlowSnippetDTO instantiateTemplate(String groupId, Double originX, Double originY, String encodingVersion, FlowSnippetDTO requestSnippet, String idGenerationSeed) {
ProcessGroup group = locateProcessGroup(flowController, groupId);
try {
// copy the template which pre-processes all ids
FlowSnippetDTO snippet = snippetUtils.copy(requestSnippet, group, idGenerationSeed, false);
// calculate scaling factors based on the template encoding version attempt to parse the encoding version.
// get the major version, or 0 if no version could be parsed
final FlowEncodingVersion templateEncodingVersion = FlowEncodingVersion.parse(encodingVersion);
int templateEncodingMajorVersion = templateEncodingVersion != null ? templateEncodingVersion.getMajorVersion() : 0;
// based on the major version < 1, use the default scaling factors. Otherwise, don't scale (use factor of 1.0)
double factorX = templateEncodingMajorVersion < 1 ? FlowController.DEFAULT_POSITION_SCALE_FACTOR_X : 1.0;
double factorY = templateEncodingMajorVersion < 1 ? FlowController.DEFAULT_POSITION_SCALE_FACTOR_Y : 1.0;
// reposition and scale the template contents
org.apache.nifi.util.SnippetUtils.moveAndScaleSnippet(snippet, originX, originY, factorX, factorY);
// find all the child process groups in each process group in the top level of this snippet
final List<ProcessGroupDTO> childProcessGroups = org.apache.nifi.util.SnippetUtils.findAllProcessGroups(snippet);
// scale (but don't reposition) child process groups
childProcessGroups.stream().forEach(processGroup -> org.apache.nifi.util.SnippetUtils.scaleSnippet(processGroup.getContents(), factorX, factorY));
// instantiate the template into this group
flowController.instantiateSnippet(group, snippet);
return snippet;
} catch (ProcessorInstantiationException pie) {
throw new NiFiCoreException(String.format("Unable to instantiate template because processor type '%s' is unknown to this NiFi.", StringUtils.substringAfterLast(pie.getMessage(), ".")));
}
}
use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.
the class ApplicationStartupContextListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
final ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
final NiFiProperties properties = ctx.getBean("nifiProperties", NiFiProperties.class);
try {
flowService = ctx.getBean("flowService", FlowService.class);
flowController = ctx.getBean("flowController", FlowController.class);
requestReplicator = ctx.getBean("requestReplicator", RequestReplicator.class);
// the flow loading here when not clustered resolves this.
if (!properties.isNode()) {
logger.info("Starting Flow Controller...");
// start and load the flow
flowService.start();
flowService.load(null);
/*
* Start up all processors if specified.
*
* When operating as the node, the cluster manager controls
* which processors should start. As part of the flow
* reloading actions, the node will start the necessary
* processors.
*/
flowController.onFlowInitialized(properties.getAutoResumeState());
logger.info("Flow Controller started successfully.");
}
} catch (BeansException | RepositoryPurgeException | IOException e) {
shutdown();
throw new NiFiCoreException("Unable to start Flow Controller.", e);
}
try {
// attempt to get a few beans that we want to to ensure properly created since they are lazily initialized
ctx.getBean("loginIdentityProvider", LoginIdentityProvider.class);
ctx.getBean("authorizer", Authorizer.class);
} catch (final BeansException e) {
shutdown();
throw new NiFiCoreException("Unable to start Flow Controller.", e);
}
}
use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.
the class FlowRegistryDAO method getFlowsForUser.
@Override
public Set<VersionedFlow> getFlowsForUser(String registryId, String bucketId, NiFiUser user) {
try {
final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(registryId);
if (flowRegistry == null) {
throw new IllegalArgumentException("The specified registry id is unknown to this NiFi.");
}
final Set<VersionedFlow> flows = flowRegistry.getFlows(bucketId, user);
final Set<VersionedFlow> sortedFlows = new TreeSet<>((f1, f2) -> f1.getName().compareTo(f2.getName()));
sortedFlows.addAll(flows);
return sortedFlows;
} catch (final IOException | NiFiRegistryException ioe) {
throw new NiFiCoreException("Unable to obtain listing of flows for bucket with ID " + bucketId + ": " + ioe, ioe);
}
}
Aggregations