Search in sources :

Example 6 with NifiComponentNotFoundException

use of com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException in project kylo by Teradata.

the class NiFiProcessGroupsRestClientV1 method create.

@Nonnull
@Override
public ProcessGroupDTO create(@Nonnull String parentProcessGroupId, @Nonnull String name) {
    final ProcessGroupEntity entity = new ProcessGroupEntity();
    final ProcessGroupDTO processGroup = new ProcessGroupDTO();
    processGroup.setName(name);
    entity.setComponent(processGroup);
    final RevisionDTO revision = new RevisionDTO();
    revision.setVersion(0L);
    entity.setRevision(revision);
    try {
        return client.post(BASE_PATH + parentProcessGroupId + "/process-groups", entity, ProcessGroupEntity.class).getComponent();
    } catch (final NotFoundException e) {
        throw new NifiComponentNotFoundException(parentProcessGroupId, NifiConstants.NIFI_COMPONENT_TYPE.PROCESS_GROUP, e);
    }
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Nonnull(javax.annotation.Nonnull)

Example 7 with NifiComponentNotFoundException

use of com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException in project kylo by Teradata.

the class NiFiProcessorsRestClientV1 method update.

@Nonnull
@Override
public ProcessorDTO update(@Nonnull final ProcessorDTO processor) {
    final ProcessorEntity entity = new ProcessorEntity();
    entity.setComponent(processor);
    return update(entity).orElseThrow(() -> new NifiComponentNotFoundException(processor.getId(), NifiConstants.NIFI_COMPONENT_TYPE.PROCESSOR, null));
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) Nonnull(javax.annotation.Nonnull)

Example 8 with NifiComponentNotFoundException

use of com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException in project kylo by Teradata.

the class DatasourceModelTransform method updateDomain.

/**
 * Updates the specified domain object with properties from the specified REST object.
 *
 * @param domain the domain object
 * @param ds     the REST object
 */
private void updateDomain(@Nonnull final com.thinkbiganalytics.metadata.api.datasource.UserDatasource domain, @Nonnull final JdbcDatasource ds) {
    updateDomain(domain, (UserDatasource) ds);
    domain.getDetails().map(JdbcDatasourceDetails.class::cast).ifPresent(details -> {
        // Look for changed properties
        final Map<String, String> properties = new HashMap<>();
        if (StringUtils.isNotBlank(ds.getDatabaseConnectionUrl())) {
            properties.put(DatasourceConstants.DATABASE_CONNECTION_URL, ds.getDatabaseConnectionUrl());
        }
        if (StringUtils.isNotBlank(ds.getDatabaseDriverClassName())) {
            properties.put(DatasourceConstants.DATABASE_DRIVER_CLASS_NAME, ds.getDatabaseDriverClassName());
        }
        if (ds.getDatabaseDriverLocation() != null) {
            properties.put(DatasourceConstants.DATABASE_DRIVER_LOCATION, ds.getDatabaseDriverLocation());
        }
        if (ds.getDatabaseUser() != null) {
            properties.put(DatasourceConstants.DATABASE_USER, ds.getDatabaseUser());
        }
        if (ds.getPassword() != null) {
            details.setPassword(encryptor.encrypt(ds.getPassword()));
            properties.put(DatasourceConstants.PASSWORD, StringUtils.isNotEmpty(ds.getPassword()) ? ds.getPassword() : null);
        }
        // Update or create the controller service
        ControllerServiceDTO controllerService = null;
        if (details.getControllerServiceId().isPresent()) {
            controllerService = new ControllerServiceDTO();
            controllerService.setId(details.getControllerServiceId().get());
            controllerService.setName(ds.getName());
            controllerService.setComments(ds.getDescription());
            controllerService.setProperties(properties);
            try {
                controllerService = nifiRestClient.controllerServices().updateServiceAndReferencingComponents(controllerService);
                ds.setControllerServiceId(controllerService.getId());
            } catch (final NifiComponentNotFoundException e) {
                log.warn("Controller service is missing for datasource: {}", domain.getId(), e);
                controllerService = null;
            }
        }
        if (controllerService == null) {
            controllerService = new ControllerServiceDTO();
            controllerService.setType("org.apache.nifi.dbcp.DBCPConnectionPool");
            controllerService.setName(ds.getName());
            controllerService.setComments(ds.getDescription());
            controllerService.setProperties(properties);
            final ControllerServiceDTO newControllerService = nifiRestClient.controllerServices().create(controllerService);
            try {
                nifiRestClient.controllerServices().updateStateById(newControllerService.getId(), NiFiControllerServicesRestClient.State.ENABLED);
            } catch (final NifiClientRuntimeException nifiException) {
                log.error("Failed to enable controller service for datasource: {}", domain.getId(), nifiException);
                nifiRestClient.controllerServices().disableAndDeleteAsync(newControllerService.getId());
                throw nifiException;
            }
            details.setControllerServiceId(newControllerService.getId());
            ds.setControllerServiceId(newControllerService.getId());
        }
    });
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) HashMap(java.util.HashMap) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)

Example 9 with NifiComponentNotFoundException

use of com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException in project kylo by Teradata.

the class ImportReusableTemplate method removeConnectionsAndInputs.

private boolean removeConnectionsAndInputs() {
    Optional<TemplateRemoteInputPortConnections> existingRemoteProcessInputPortInformation = getExistingRemoteProcessInputPortInformation();
    if (existingRemoteProcessInputPortInformation.isPresent()) {
        // find the input ports that are 'existing' but not 'selected' .  These should be deleted
        Set<String> inputPortNamesToRemove = remoteProcessGroupInputPortMap.values().stream().filter((remoteInputPort -> !remoteInputPort.isSelected() && existingRemoteProcessInputPortInformation.get().getExistingRemoteInputPortNames().contains(remoteInputPort.getInputPortName()))).map(remoteInputPort -> remoteInputPort.getInputPortName()).collect(Collectors.toSet());
        // Find the connections that match the input ports that are to be removed
        Set<ConnectionDTO> connectionsToRemove = existingRemoteProcessInputPortInformation.get().getExistingRemoteConnectionsToTemplate().stream().filter(connectionDTO -> inputPortNamesToRemove.contains(connectionDTO.getSource().getName())).collect(Collectors.toSet());
        log.info("Removing input ports {}", inputPortNamesToRemove);
        Set<ConnectionDTO> connectionsWithQueue = new HashSet<>();
        // first validate the queues are empty ... if not warn user the following ports cant be deleted and rollback
        connectionsToRemove.stream().forEach(connection -> {
            Optional<ConnectionStatusEntity> connectionStatus = nifiRestClient.getNiFiRestClient().connections().getConnectionStatus(connection.getId());
            if (connectionStatus.isPresent() && connectionStatus.get().getConnectionStatus().getAggregateSnapshot().getFlowFilesQueued() > 0) {
                connectionsWithQueue.add(connection);
            }
        });
        if (!connectionsWithQueue.isEmpty()) {
            UploadProgressMessage importStatusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Unable to remove inputPort and connection for :" + connectionsWithQueue.stream().map(c -> c.getSource().getName()).collect(Collectors.joining(",")) + ". The Queues are not empty. Failed to import template: " + importTemplate.getTemplateName(), true, false);
            importTemplate.setValid(false);
            importTemplate.setSuccess(false);
            return false;
        } else {
            connectionsToRemove.stream().forEach(connection -> {
                nifiRestClient.deleteConnection(connection, false);
                getItemsCreated().addDeletedRemoteInputPortConnection(connection);
                try {
                    PortDTO deletedPort = nifiRestClient.getNiFiRestClient().ports().deleteInputPort(connection.getSource().getId());
                    if (deletedPort != null) {
                        getItemsCreated().addDeletedRemoteInputPort(deletedPort);
                    }
                } catch (NifiComponentNotFoundException e) {
                // this is ok to catch as its deleted already
                }
            });
            UploadProgressMessage importStatusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Removed inputPort and connection for :" + connectionsToRemove.stream().map(c -> c.getSource().getName()).collect(Collectors.joining(",")) + " for template: " + importTemplate.getTemplateName(), true, true);
        }
        return true;
    }
    return true;
}
Also used : UploadProgressService(com.thinkbiganalytics.feedmgr.service.UploadProgressService) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) LoggerFactory(org.slf4j.LoggerFactory) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil) StringUtils(org.apache.commons.lang3.StringUtils) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) NifiFlowUtil(com.thinkbiganalytics.nifi.rest.support.NifiFlowUtil) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) ReusableTemplateCreationCallback(com.thinkbiganalytics.nifi.feedmgr.ReusableTemplateCreationCallback) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) RegisteredTemplateCache(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateCache) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ImportTemplateOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportTemplateOptions) Optional(java.util.Optional) NiFiTemplateImport(com.thinkbiganalytics.feedmgr.service.template.importing.model.NiFiTemplateImport) ImportComponent(com.thinkbiganalytics.feedmgr.rest.ImportComponent) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) HashMap(java.util.HashMap) ImportSection(com.thinkbiganalytics.feedmgr.rest.ImportSection) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) Nullable(javax.annotation.Nullable) NiFiClusterSummary(com.thinkbiganalytics.nifi.rest.model.NiFiClusterSummary) Logger(org.slf4j.Logger) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) TemplateRemoteInputPortConnections(com.thinkbiganalytics.feedmgr.rest.model.TemplateRemoteInputPortConnections) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) TemplateRemoteInputPortConnections(com.thinkbiganalytics.feedmgr.rest.model.TemplateRemoteInputPortConnections) HashSet(java.util.HashSet)

Example 10 with NifiComponentNotFoundException

use of com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException in project kylo by Teradata.

the class NifiConnectionOrderVisitor method searchConnectionMatchingDestination.

private ConnectionDTO searchConnectionMatchingDestination(String parentGroupId, String sourceId) {
    try {
        ProcessGroupDTO parent = null;
        try {
            parent = getGroup(parentGroupId);
        } catch (NifiComponentNotFoundException e) {
            log.debug("Exception searching Connection matching the destination. Parent Group ID: " + parentGroupId + ", and destinationId of  " + sourceId);
        }
        if (parent != null) {
            // get Contents of this parent
            NifiVisitableProcessGroup visitableProcessGroup = new NifiVisitableProcessGroup(parent);
            ConnectionDTO conn = visitableProcessGroup.getConnectionMatchingDestinationId(sourceId);
            if (conn != null) {
                return conn;
            }
            if (conn == null && parent.getParentGroupId() != null) {
                return searchConnectionMatchingSource(parent.getParentGroupId(), sourceId);
            }
        }
    } catch (Exception e) {
        log.error("Exception searching Connection matching the destination.  Parent Group ID: " + parentGroupId + ", and source of  " + sourceId);
    }
    return null;
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)

Aggregations

NifiComponentNotFoundException (com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)22 Nonnull (javax.annotation.Nonnull)10 NotFoundException (javax.ws.rs.NotFoundException)10 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)10 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)6 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)6 HashMap (java.util.HashMap)5 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)5 PortEntity (org.apache.nifi.web.api.entity.PortEntity)5 NifiClientRuntimeException (com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)4 NifiVisitableProcessGroup (com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup)4 LegacyNifiRestClient (com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient)3 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)3 NifiConstants (com.thinkbiganalytics.nifi.rest.support.NifiConstants)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Iterables (com.google.common.collect.Iterables)2 ReusableTemplateConnectionInfo (com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo)2 NifiPropertyUtil (com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil)2 HashSet (java.util.HashSet)2