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);
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations