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