use of org.apache.nifi.web.api.dto.RevisionDTO in project kylo by Teradata.
the class NiFiControllerServicesRestClientV1 method create.
@Nonnull
@Override
public ControllerServiceDTO create(@Nonnull ControllerServiceDTO controllerService) {
final ControllerServiceEntity entity = new ControllerServiceEntity();
entity.setComponent(controllerService);
final RevisionDTO revision = new RevisionDTO();
revision.setVersion(0L);
entity.setRevision(revision);
return client.post("/process-groups/root/controller-services", entity, ControllerServiceEntity.class).getComponent();
}
use of org.apache.nifi.web.api.dto.RevisionDTO in project kylo by Teradata.
the class NiFiPortsRestClientV1 method updateInputPortEntity.
private PortEntity updateInputPortEntity(@Nonnull final String processGroupId, @Nonnull final PortDTO inputPort, Integer retryAttempt) {
// Get revision
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);
}
if (current == null || (current != null && isModified(current.getComponent(), inputPort))) {
boolean update = true;
// if we are trying to do anything but disable the port and the port is currently invalid prevent it from updating.
if (current != null && current.getStatus().getRunStatus().equalsIgnoreCase("invalid") && !inputPort.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name())) {
update = false;
} else if (StringUtils.isNotBlank(inputPort.getId()) && NifiProcessUtil.PROCESS_STATE.RUNNING.name().equals(inputPort.getState())) {
// only mark input port as running if we have connections to it
// NIFI bug
Set<ConnectionDTO> connectionDTOS = client.connections().findConnectionsToEntity(processGroupId, inputPort.getId());
// find this ports processgroup parent
Optional<ProcessGroupDTO> group = client.processGroups().findById(processGroupId, false, false);
if (group.isPresent() && StringUtils.isNotBlank(group.get().getParentGroupId())) {
Set<ConnectionDTO> upstreamConnections = client.connections().findConnectionsToEntity(group.get().getParentGroupId(), inputPort.getId());
if (upstreamConnections != null && !upstreamConnections.isEmpty()) {
if (connectionDTOS == null) {
connectionDTOS = new HashSet<>();
}
connectionDTOS = Stream.concat(connectionDTOS.stream(), upstreamConnections.stream()).collect(Collectors.toSet());
}
}
boolean isRootProcessGroup = client.processGroups().isRoot(processGroupId);
// always update root input portsgroups as they will be needed to be running if used by Remote Process Groups
if (!isRootProcessGroup && (connectionDTOS == null || connectionDTOS.isEmpty() || connectionDTOS.stream().noneMatch(connectionDTO -> connectionDTO.getDestination() != null && connectionDTO.getDestination().getId().equals(inputPort.getId())))) {
log.warn("System will not start the input port [{}] [{}] in the process group [{}] since there are no upstream connections to it ", inputPort.getId(), inputPort.getName(), processGroupId);
update = false;
}
}
if (update) {
if (StringUtils.isNotBlank(inputPort.getState())) {
// if trying to make a DISABLED port RUNNING you need to make it STOPPED first and then mark it as RUNNING
if (current != null && current.getComponent().getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name()) && inputPort.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.RUNNING.name())) {
// first need to make it ENABLED
inputPort.setState(NifiProcessUtil.PROCESS_STATE.STOPPED.name());
current = updateInputPortEntity(processGroupId, inputPort, retryAttempt);
inputPort.setState(NifiProcessUtil.PROCESS_STATE.RUNNING.name());
}
// if trying to make a RUNNING port DISABLED you need to make it STOPPED first and then mark it as DISABLED
if (current != null && current.getComponent().getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.RUNNING.name()) && inputPort.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name())) {
// first need to make it ENABLED
inputPort.setState(NifiProcessUtil.PROCESS_STATE.STOPPED.name());
current = updateInputPortEntity(processGroupId, inputPort, retryAttempt);
inputPort.setState(NifiProcessUtil.PROCESS_STATE.DISABLED.name());
}
}
// 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);
} catch (final NotFoundException e) {
throw new NifiComponentNotFoundException(inputPort.getId(), NifiConstants.NIFI_COMPONENT_TYPE.INPUT_PORT, e);
} catch (Exception e) {
if (retryAttempt < 3) {
retryAttempt++;
log.info("An exception occurred attempting to update input port {}. Retrying update {}/3", inputPort.getId(), retryAttempt);
delay(500L);
return updateInputPortEntity(processGroupId, inputPort, retryAttempt);
} else {
log.info("An exception occurred attempting to update input port {}. Max retries of 3 reached.", inputPort.getId(), e);
throw e;
}
}
}
}
if (current == null) {
PortEntity entity = new PortEntity();
entity.setComponent(inputPort);
entity.setPortType(inputPort.getType());
return entity;
} else {
return current;
}
}
use of org.apache.nifi.web.api.dto.RevisionDTO in project kylo by Teradata.
the class NiFiPortsRestClientV1 method updateOutputPortEntity.
@Nonnull
private PortEntity updateOutputPortEntity(@Nonnull final String processGroupId, @Nonnull final PortDTO outputPort, Integer retryAttempt) {
// Get revision
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);
}
PortDTO currentPort = current != null ? current.getComponent() : null;
boolean update = true;
// if we are trying to do anything but disable the port and the port is currently invalid prevent it from updating.
if (current != null && current.getStatus().getRunStatus().equalsIgnoreCase("invalid") && !outputPort.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name())) {
update = false;
} else if (StringUtils.isNotBlank(outputPort.getId()) && NifiProcessUtil.PROCESS_STATE.RUNNING.name().equals(outputPort.getState())) {
// only mark port as running if we have connections to it
// NIFI bug
Set<ConnectionDTO> connectionDTOS = client.connections().findConnectionsToEntity(processGroupId, outputPort.getId());
if (connectionDTOS == null || connectionDTOS.isEmpty() || connectionDTOS.stream().noneMatch(connectionDTO -> (connectionDTO.getSource() != null && connectionDTO.getSource().getId().equals(outputPort.getId())) || (connectionDTO.getDestination() != null && connectionDTO.getDestination().getId().equalsIgnoreCase(outputPort.getId())))) {
log.warn("System will not start the output port [{}] [{}] in the process group [{}] since there are no connections to it ", outputPort.getId(), outputPort.getName(), processGroupId);
update = false;
}
}
if (update) {
if (StringUtils.isNotBlank(outputPort.getState())) {
// if trying to make a DISABLED port RUNNING you need to make it STOPPED first and then mark it as RUNNING
if (current != null && current.getComponent().getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name()) && outputPort.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.RUNNING.name())) {
// first need to make it ENABLED
outputPort.setState(NifiProcessUtil.PROCESS_STATE.STOPPED.name());
current = updateOutputPortEntity(processGroupId, outputPort, retryAttempt);
delay(500L);
outputPort.setState(NifiProcessUtil.PROCESS_STATE.RUNNING.name());
}
// if trying to make a RUNNING port DISABLED you need to make it STOPPED first and then mark it as DISABLED
if (current != null && current.getComponent().getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.RUNNING.name()) && outputPort.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name())) {
// first need to make it ENABLED
outputPort.setState(NifiProcessUtil.PROCESS_STATE.STOPPED.name());
current = updateOutputPortEntity(processGroupId, outputPort, retryAttempt);
delay(500L);
outputPort.setState(NifiProcessUtil.PROCESS_STATE.DISABLED.name());
}
}
// 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);
} catch (final NotFoundException e) {
throw new NifiComponentNotFoundException(outputPort.getId(), NifiConstants.NIFI_COMPONENT_TYPE.OUTPUT_PORT, e);
} catch (Exception e) {
if (retryAttempt < 3) {
retryAttempt++;
log.info("An exception occurred attempting to update output port {}. Retrying update {}/3", outputPort.getId(), retryAttempt);
delay(500L);
return updateOutputPortEntity(processGroupId, outputPort, retryAttempt);
} else {
log.info("An exception occurred attempting to update output port {}. Max retries of 3 reached.", outputPort.getId(), e);
throw e;
}
}
}
if (current == null) {
PortEntity entity = new PortEntity();
entity.setComponent(outputPort);
entity.setPortType(outputPort.getType());
return entity;
} else {
return current;
}
}
use of org.apache.nifi.web.api.dto.RevisionDTO in project kylo by Teradata.
the class NiFiProcessGroupsRestClientV1 method create.
public ProcessGroupDTO create(@Nonnull String parentProcessGroupId, @Nonnull String name, @Nullable Double x, @Nullable Double y) {
final ProcessGroupEntity entity = new ProcessGroupEntity();
final ProcessGroupDTO processGroup = new ProcessGroupDTO();
processGroup.setName(name);
if (x != null && y != null) {
processGroup.setPosition(new PositionDTO(x, y));
}
entity.setComponent(processGroup);
final RevisionDTO revision = new RevisionDTO();
revision.setVersion(0L);
entity.setRevision(revision);
try {
return getClient().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);
}
}
use of org.apache.nifi.web.api.dto.RevisionDTO 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);
}
}
Aggregations