Search in sources :

Example 11 with ControllerServiceEntity

use of org.apache.nifi.web.api.entity.ControllerServiceEntity in project nifi by apache.

the class EntityFactory method createControllerServiceEntity.

public ControllerServiceEntity createControllerServiceEntity(final ControllerServiceDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final List<BulletinEntity> bulletins) {
    final ControllerServiceEntity entity = new ControllerServiceEntity();
    entity.setRevision(revision);
    if (dto != null) {
        entity.setPermissions(permissions);
        entity.setId(dto.getId());
        entity.setPosition(dto.getPosition());
        if (permissions != null && permissions.getCanRead()) {
            entity.setComponent(dto);
            entity.setBulletins(bulletins);
        }
    }
    return entity;
}
Also used : ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity)

Example 12 with ControllerServiceEntity

use of org.apache.nifi.web.api.entity.ControllerServiceEntity in project nifi by apache.

the class LocalComponentLifecycle method updateAffectedControllerServices.

/**
 * Updates the affected controller services in the specified updateRequest with the serviceEntities.
 *
 * @param serviceEntities service entities
 * @param affectedServices all Controller Services whose state should be equal to the given desired state
 */
private void updateAffectedControllerServices(final Set<ControllerServiceEntity> serviceEntities, final Map<String, AffectedComponentEntity> affectedServices) {
    // update the affected components
    serviceEntities.stream().filter(entity -> affectedServices.containsKey(entity.getId())).forEach(entity -> {
        final AffectedComponentEntity affectedComponentEntity = affectedServices.get(entity.getId());
        affectedComponentEntity.setRevision(entity.getRevision());
        // only consider update this component if the user had permissions to it
        if (Boolean.TRUE.equals(affectedComponentEntity.getPermissions().getCanRead())) {
            final AffectedComponentDTO affectedComponent = affectedComponentEntity.getComponent();
            affectedComponent.setState(entity.getComponent().getState());
            if (Boolean.TRUE.equals(entity.getPermissions().getCanRead())) {
                affectedComponent.setValidationErrors(entity.getComponent().getValidationErrors());
            }
        }
    });
}
Also used : NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) Revision(org.apache.nifi.web.Revision) Logger(org.slf4j.Logger) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) LoggerFactory(org.slf4j.LoggerFactory) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) Set(java.util.Set) RevisionManager(org.apache.nifi.web.revision.RevisionManager) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ScheduledState(org.apache.nifi.controller.ScheduledState) Map(java.util.Map) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity) URI(java.net.URI) DtoFactory(org.apache.nifi.web.api.dto.DtoFactory) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity)

Example 13 with ControllerServiceEntity

use of org.apache.nifi.web.api.entity.ControllerServiceEntity in project nifi by apache.

the class ControllerServicesEndpointMerger method merge.

@Override
public final NodeResponse merge(final URI uri, final String method, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses, final NodeResponse clientResponse) {
    if (!canHandle(uri, method)) {
        throw new IllegalArgumentException("Cannot use Endpoint Mapper of type " + getClass().getSimpleName() + " to map responses for URI " + uri + ", HTTP Method " + method);
    }
    final ControllerServicesEntity responseEntity = clientResponse.getClientResponse().readEntity(ControllerServicesEntity.class);
    final Set<ControllerServiceEntity> controllerServiceEntities = responseEntity.getControllerServices();
    final Map<String, Map<NodeIdentifier, ControllerServiceEntity>> entityMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final ControllerServicesEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(ControllerServicesEntity.class);
        final Set<ControllerServiceEntity> nodeControllerServiceEntities = nodeResponseEntity.getControllerServices();
        for (final ControllerServiceEntity nodeControllerServiceEntity : nodeControllerServiceEntities) {
            final NodeIdentifier nodeId = nodeResponse.getNodeId();
            Map<NodeIdentifier, ControllerServiceEntity> innerMap = entityMap.get(nodeId);
            if (innerMap == null) {
                innerMap = new HashMap<>();
                entityMap.put(nodeControllerServiceEntity.getId(), innerMap);
            }
            innerMap.put(nodeResponse.getNodeId(), nodeControllerServiceEntity);
        }
    }
    ControllerServicesEntityMerger.mergeControllerServices(controllerServiceEntities, entityMap);
    // create a new client response
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ControllerServicesEntity(org.apache.nifi.web.api.entity.ControllerServicesEntity) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with ControllerServiceEntity

use of org.apache.nifi.web.api.entity.ControllerServiceEntity in project kylo by Teradata.

the class NiFiProcessGroupsRestClientV1 method createControllerService.

@Nonnull
@Override
public ControllerServiceDTO createControllerService(@Nonnull final String processGroupId, @Nonnull final ControllerServiceDTO controllerService) {
    final ControllerServiceEntity entity = new ControllerServiceEntity();
    entity.setComponent(controllerService);
    final RevisionDTO revision = new RevisionDTO();
    revision.setVersion(0L);
    entity.setRevision(revision);
    try {
        return client.post(BASE_PATH + processGroupId + "/controller-services", entity, ControllerServiceEntity.class).getComponent();
    } catch (final NotFoundException e) {
        throw new NifiComponentNotFoundException(processGroupId, NifiConstants.NIFI_COMPONENT_TYPE.PROCESS_GROUP, e);
    }
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) 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 15 with ControllerServiceEntity

use of org.apache.nifi.web.api.entity.ControllerServiceEntity in project kylo by Teradata.

the class NiFiReportingTaskRestClientV1 method createReportingTaskControllerService.

@Override
public ControllerServiceDTO createReportingTaskControllerService(@Nonnull ControllerServiceDTO controllerService) {
    ControllerServiceEntity entity = new ControllerServiceEntity();
    entity.setComponent(controllerService);
    final RevisionDTO revision = new RevisionDTO();
    revision.setVersion(0L);
    entity.setRevision(revision);
    ControllerServiceEntity updatedService = client.post(CREATE_CONTROLLER_SERVICE_PATH, entity, ControllerServiceEntity.class);
    if (updatedService != null) {
        return updatedService.getComponent();
    } else {
        return null;
    }
}
Also used : ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Aggregations

ControllerServiceEntity (org.apache.nifi.web.api.entity.ControllerServiceEntity)24 Map (java.util.Map)11 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Consumes (javax.ws.rs.Consumes)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)10 HashMap (java.util.HashMap)9 Set (java.util.Set)9 Function (java.util.function.Function)9 Collectors (java.util.stream.Collectors)9 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)9 Revision (org.apache.nifi.web.Revision)9 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)9 ActivateControllerServicesEntity (org.apache.nifi.web.api.entity.ActivateControllerServicesEntity)9 ScheduledState (org.apache.nifi.controller.ScheduledState)8 ControllerServiceState (org.apache.nifi.controller.service.ControllerServiceState)8 AffectedComponentDTO (org.apache.nifi.web.api.dto.AffectedComponentDTO)8 DtoFactory (org.apache.nifi.web.api.dto.DtoFactory)8