Search in sources :

Example 6 with NiFiCoreException

use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.

the class StandardControllerServiceDAO method updateBundle.

private void updateBundle(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) {
    final BundleDTO bundleDTO = controllerServiceDTO.getBundle();
    if (bundleDTO != null) {
        final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(controllerService.getCanonicalClassName(), bundleDTO);
        final BundleCoordinate existingCoordinate = controllerService.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(controllerService.getCanonicalClassName(), incomingCoordinate);
                final Set<URL> additionalUrls = controllerService.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors());
                flowController.reload(controllerService, controllerService.getCanonicalClassName(), incomingCoordinate, additionalUrls);
            } catch (ControllerServiceInstantiationException e) {
                throw new NiFiCoreException(String.format("Unable to update controller service %s from %s to %s due to: %s", controllerServiceDTO.getId(), controllerService.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e);
            }
        }
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL)

Example 7 with NiFiCoreException

use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.

the class StandardControllerServiceDAO method createControllerService.

@Override
public ControllerServiceNode createControllerService(final ControllerServiceDTO controllerServiceDTO) {
    // ensure the type is specified
    if (controllerServiceDTO.getType() == null) {
        throw new IllegalArgumentException("The controller service type must be specified.");
    }
    try {
        // create the controller service
        final ControllerServiceNode controllerService = serviceProvider.createControllerService(controllerServiceDTO.getType(), controllerServiceDTO.getId(), BundleUtils.getBundle(controllerServiceDTO.getType(), controllerServiceDTO.getBundle()), Collections.emptySet(), true);
        // ensure we can perform the update
        verifyUpdate(controllerService, controllerServiceDTO);
        // perform the update
        configureControllerService(controllerService, controllerServiceDTO);
        final String groupId = controllerServiceDTO.getParentGroupId();
        if (groupId == null) {
            flowController.addRootControllerService(controllerService);
        } else {
            final ProcessGroup group;
            if (groupId.equals(ROOT_GROUP_ID_ALIAS)) {
                group = flowController.getGroup(flowController.getRootGroupId());
            } else {
                group = flowController.getGroup(flowController.getRootGroupId()).findProcessGroup(groupId);
            }
            if (group == null) {
                throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
            }
            group.addControllerService(controllerService);
        }
        return controllerService;
    } catch (final ControllerServiceInstantiationException csie) {
        throw new NiFiCoreException(csie.getMessage(), csie);
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException)

Example 8 with NiFiCoreException

use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.

the class StandardProcessorDAO method createProcessor.

@Override
public ProcessorNode createProcessor(final String groupId, ProcessorDTO processorDTO) {
    if (processorDTO.getParentGroupId() != null && !flowController.areGroupsSame(groupId, processorDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the Processor is being added.");
    }
    // ensure the type is specified
    if (processorDTO.getType() == null) {
        throw new IllegalArgumentException("The processor type must be specified.");
    }
    // get the group to add the processor to
    ProcessGroup group = locateProcessGroup(flowController, groupId);
    try {
        // attempt to create the processor
        ProcessorNode processor = flowController.createProcessor(processorDTO.getType(), processorDTO.getId(), BundleUtils.getBundle(processorDTO.getType(), processorDTO.getBundle()));
        // ensure we can perform the update before we add the processor to the flow
        verifyUpdate(processor, processorDTO);
        // add the processor to the group
        group.addProcessor(processor);
        // configure the processor
        configureProcessor(processor, processorDTO);
        return processor;
    } catch (ProcessorInstantiationException pse) {
        throw new NiFiCoreException(String.format("Unable to create processor of type %s due to: %s", processorDTO.getType(), pse.getMessage()), pse);
    } catch (IllegalStateException | ComponentLifeCycleException ise) {
        throw new NiFiCoreException(ise.getMessage(), ise);
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException)

Example 9 with NiFiCoreException

use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.

the class StandardProcessorDAO method updateBundle.

private void updateBundle(ProcessorNode processor, ProcessorDTO processorDTO) {
    final BundleDTO bundleDTO = processorDTO.getBundle();
    if (bundleDTO != null) {
        final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(processor.getCanonicalClassName(), bundleDTO);
        final BundleCoordinate existingCoordinate = processor.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(processor.getCanonicalClassName(), incomingCoordinate);
                final Set<URL> additionalUrls = processor.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors());
                flowController.reload(processor, processor.getCanonicalClassName(), incomingCoordinate, additionalUrls);
            } catch (ProcessorInstantiationException e) {
                throw new NiFiCoreException(String.format("Unable to update processor %s from %s to %s due to: %s", processorDTO.getId(), processor.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e);
            }
        }
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL)

Example 10 with NiFiCoreException

use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.

the class StandardReportingTaskDAO method createReportingTask.

@Override
public ReportingTaskNode createReportingTask(final ReportingTaskDTO reportingTaskDTO) {
    // ensure the type is specified
    if (reportingTaskDTO.getType() == null) {
        throw new IllegalArgumentException("The reporting task type must be specified.");
    }
    try {
        // create the reporting task
        final ReportingTaskNode reportingTask = reportingTaskProvider.createReportingTask(reportingTaskDTO.getType(), reportingTaskDTO.getId(), BundleUtils.getBundle(reportingTaskDTO.getType(), reportingTaskDTO.getBundle()), true);
        // ensure we can perform the update
        verifyUpdate(reportingTask, reportingTaskDTO);
        // perform the update
        configureReportingTask(reportingTask, reportingTaskDTO);
        return reportingTask;
    } catch (ReportingTaskInstantiationException rtie) {
        throw new NiFiCoreException(rtie.getMessage(), rtie);
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode)

Aggregations

NiFiCoreException (org.apache.nifi.web.NiFiCoreException)20 IOException (java.io.IOException)7 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)6 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)5 ProcessGroup (org.apache.nifi.groups.ProcessGroup)5 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)4 ConfigurableComponent (org.apache.nifi.components.ConfigurableComponent)4 ScheduledState (org.apache.nifi.controller.ScheduledState)4 URL (java.net.URL)3 TreeSet (java.util.TreeSet)3 ComponentLifeCycleException (org.apache.nifi.controller.exception.ComponentLifeCycleException)3 ReportingTaskInstantiationException (org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)3 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)3 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)3 FlowRegistry (org.apache.nifi.registry.flow.FlowRegistry)3 BundleDTO (org.apache.nifi.web.api.dto.BundleDTO)3 ParseException (java.text.ParseException)2 HashSet (java.util.HashSet)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 Port (org.apache.nifi.connectable.Port)2