Search in sources :

Example 26 with PortEntity

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

the class OutputPortsEndpointMerger 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 OutputPortsEntity responseEntity = clientResponse.getClientResponse().readEntity(OutputPortsEntity.class);
    final Set<PortEntity> portEntities = responseEntity.getOutputPorts();
    final Map<String, Map<NodeIdentifier, PortEntity>> entityMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final OutputPortsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(OutputPortsEntity.class);
        final Set<PortEntity> nodePortEntities = nodeResponseEntity.getOutputPorts();
        for (final PortEntity nodePortEntity : nodePortEntities) {
            final NodeIdentifier nodeId = nodeResponse.getNodeId();
            Map<NodeIdentifier, PortEntity> innerMap = entityMap.get(nodeId);
            if (innerMap == null) {
                innerMap = new HashMap<>();
                entityMap.put(nodePortEntity.getId(), innerMap);
            }
            innerMap.put(nodeResponse.getNodeId(), nodePortEntity);
        }
    }
    PortsEntityMerger.mergePorts(portEntities, entityMap);
    // create a new client response
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) OutputPortsEntity(org.apache.nifi.web.api.entity.OutputPortsEntity) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) Map(java.util.Map) HashMap(java.util.HashMap) PortEntity(org.apache.nifi.web.api.entity.PortEntity)

Example 27 with PortEntity

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

the class NiFiPortsRestClientV1 method deleteInputPort.

@Override
public PortDTO deleteInputPort(@Nonnull String portId) {
    try {
        PortEntity current = client.get("/input-ports/" + portId, null, PortEntity.class);
        if (current != null) {
            Map<String, Object> params = new HashMap<>();
            params.put("version", current.getRevision().getVersion());
            params.put("clientId", current.getRevision().getClientId());
            PortEntity inputPortsEntity = client.delete("/input-ports/" + portId, params, PortEntity.class);
            if (inputPortsEntity != null) {
                return inputPortsEntity.getComponent();
            }
        }
    } catch (NotFoundException e) {
        throw new NifiComponentNotFoundException(portId, NifiConstants.NIFI_COMPONENT_TYPE.INPUT_PORT, e);
    }
    return null;
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) HashMap(java.util.HashMap) NotFoundException(javax.ws.rs.NotFoundException) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) PortEntity(org.apache.nifi.web.api.entity.PortEntity)

Example 28 with PortEntity

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

the class NiFiPortsRestClientV1 method updateOutputPort.

@Nonnull
@Override
public PortDTO updateOutputPort(@Nonnull final String processGroupId, @Nonnull final PortDTO outputPort) {
    // Get revision
    final PortEntity current;
    try {
        current = client.get("/output-ports/" + outputPort.getId(), null, PortEntity.class);
    } catch (NotFoundException e) {
        throw new NifiComponentNotFoundException(outputPort.getId(), NifiConstants.NIFI_COMPONENT_TYPE.OUTPUT_PORT, e);
    }
    // Update output port
    final PortEntity entity = new PortEntity();
    entity.setComponent(outputPort);
    final RevisionDTO revision = new RevisionDTO();
    revision.setVersion(current.getRevision().getVersion());
    entity.setRevision(revision);
    try {
        return client.put("/output-ports/" + outputPort.getId(), entity, PortEntity.class).getComponent();
    } catch (final NotFoundException e) {
        throw new NifiComponentNotFoundException(outputPort.getId(), NifiConstants.NIFI_COMPONENT_TYPE.OUTPUT_PORT, e);
    }
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Nonnull(javax.annotation.Nonnull)

Example 29 with PortEntity

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

the class NiFiPortsRestClientV1 method updateInputPort.

@Nonnull
@Override
public PortDTO updateInputPort(@Nonnull final String processGroupId, @Nonnull final PortDTO inputPort) {
    // Get revision
    final PortEntity current;
    try {
        current = client.get("/input-ports/" + inputPort.getId(), null, PortEntity.class);
    } catch (NotFoundException e) {
        throw new NifiComponentNotFoundException(inputPort.getId(), NifiConstants.NIFI_COMPONENT_TYPE.INPUT_PORT, e);
    }
    // Update input port
    final PortEntity entity = new PortEntity();
    entity.setComponent(inputPort);
    final RevisionDTO revision = new RevisionDTO();
    revision.setVersion(current.getRevision().getVersion());
    entity.setRevision(revision);
    try {
        return client.put("/input-ports/" + inputPort.getId(), entity, PortEntity.class).getComponent();
    } catch (final NotFoundException e) {
        throw new NifiComponentNotFoundException(inputPort.getId(), NifiConstants.NIFI_COMPONENT_TYPE.INPUT_PORT, e);
    }
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Nonnull(javax.annotation.Nonnull)

Example 30 with PortEntity

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

the class NiFiProcessGroupsRestClientV1 method createInputPort.

@Nonnull
@Override
public PortDTO createInputPort(@Nonnull final String processGroupId, @Nonnull final PortDTO inputPort) {
    final PortEntity entity = new PortEntity();
    entity.setComponent(inputPort);
    final RevisionDTO revision = new RevisionDTO();
    revision.setVersion(0L);
    entity.setRevision(revision);
    try {
        return client.post(BASE_PATH + processGroupId + "/input-ports", entity, PortEntity.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) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Nonnull(javax.annotation.Nonnull)

Aggregations

PortEntity (org.apache.nifi.web.api.entity.PortEntity)52 Response (javax.ws.rs.core.Response)23 Test (org.junit.Test)18 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)17 Authorizable (org.apache.nifi.authorization.resource.Authorizable)16 PortDTO (org.apache.nifi.web.api.dto.PortDTO)16 HashMap (java.util.HashMap)13 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Map (java.util.Map)10 Consumes (javax.ws.rs.Consumes)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)10 FlowDTO (org.apache.nifi.web.api.dto.flow.FlowDTO)9 ProcessGroupFlowEntity (org.apache.nifi.web.api.entity.ProcessGroupFlowEntity)9 ConnectionEntity (org.apache.nifi.web.api.entity.ConnectionEntity)8 FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)8 LabelEntity (org.apache.nifi.web.api.entity.LabelEntity)8 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)8