use of com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException 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);
}
}
use of com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException 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);
}
}
use of com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException in project kylo by Teradata.
the class NiFiProcessGroupsRestClientV1 method createOutputPort.
@Nonnull
@Override
public PortDTO createOutputPort(@Nonnull final String processGroupId, @Nonnull final PortDTO outputPort) {
final PortEntity entity = new PortEntity();
entity.setComponent(outputPort);
final RevisionDTO revision = new RevisionDTO();
revision.setVersion(0L);
entity.setRevision(revision);
try {
return client.post(BASE_PATH + processGroupId + "/output-ports", entity, PortEntity.class).getComponent();
} catch (final NotFoundException e) {
throw new NifiComponentNotFoundException(processGroupId, NifiConstants.NIFI_COMPONENT_TYPE.PROCESS_GROUP, e);
}
}
use of com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException in project kylo by Teradata.
the class TemplateCreationHelper method instantiateFlowFromTemplate.
/**
* Instantiates the specified template in the specified process group.
*
* <p>Controller services that are created under the specified process group will be moved to the root process group. This side-effect may be removed in the future.</p>
*
* @param processGroupId the process group id
* @param templateId the template id
* @return the instantiated flow
* @throws NifiComponentNotFoundException if the process group or template does not exist
*/
@Nonnull
public TemplateInstance instantiateFlowFromTemplate(@Nonnull final String processGroupId, @Nonnull final String templateId) throws NifiComponentNotFoundException {
// Instantiate template
final NiFiRestClient nifiClient = restClient.getNiFiRestClient();
final FlowSnippetDTO templateFlow = nifiClient.processGroups().instantiateTemplate(processGroupId, templateId);
TemplateInstance instance = new TemplateInstance(templateFlow);
// Move controller services to root process group (NiFi >= v1.0)
final Set<ControllerServiceDTO> groupControllerServices = nifiClient.processGroups().getControllerServices(processGroupId);
final Map<String, String> idMap = new HashMap<>(groupControllerServices.size());
groupControllerServices.stream().filter(controllerService -> controllerService.getParentGroupId().equals(processGroupId)).forEach(groupControllerService -> {
// Delete scoped service
final String oldId = groupControllerService.getId();
nifiClient.controllerServices().delete(groupControllerService.getId());
// Create root service
final ControllerServiceDTO rootControllerService = new ControllerServiceDTO();
rootControllerService.setComments(groupControllerService.getComments());
rootControllerService.setName(groupControllerService.getName());
rootControllerService.setType(groupControllerService.getType());
ControllerServiceDTO newRootService = nifiClient.processGroups().createControllerService("root", rootControllerService);
final String rootId = newRootService.getId();
// Map old ID to new ID
idMap.put(oldId, rootId);
instance.movedScopedControllerService(groupControllerService, newRootService);
});
// Set properties on root controller services
groupControllerServices.stream().filter(controllerService -> controllerService.getParentGroupId().equals(processGroupId)).forEach(groupControllerService -> {
final Map<String, String> properties = groupControllerService.getProperties();
groupControllerService.getDescriptors().values().stream().filter(descriptor -> StringUtils.isNotBlank(descriptor.getIdentifiesControllerService())).forEach(descriptor -> {
final String name = descriptor.getName();
final String oldId = properties.get(name);
properties.put(name, idMap.get(oldId));
});
final ControllerServiceDTO rootControllerService = new ControllerServiceDTO();
rootControllerService.setId(idMap.get(groupControllerService.getId()));
rootControllerService.setProperties(properties);
nifiClient.controllerServices().update(rootControllerService);
});
// Return flow
return instance;
}
use of com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException in project kylo by Teradata.
the class TemplateCreationHelper method createTemporaryTemplateFlow.
/**
* Creates an instance of the supplied template under the temporary inspection group inside its own process group
*
* @param templateId the template to instantiate
* @return the process group holding this template
*/
public ProcessGroupDTO createTemporaryTemplateFlow(@Nonnull final String templateId) {
ProcessGroupDTO temporaryTemplateInspectionGroup = nifiObjectCache.getOrCreateTemporaryTemplateInspectionGroup();
// next create the temp group
snapshotControllerServiceReferences();
ProcessGroupDTO tempGroup = null;
try {
tempGroup = nifiRestClient.processGroups().create(temporaryTemplateInspectionGroup.getId(), "template_" + System.currentTimeMillis());
} catch (NifiComponentNotFoundException e) {
nifiObjectCache.resetTemporaryTemplateInspectionGroup();
tempGroup = nifiRestClient.processGroups().create(temporaryTemplateInspectionGroup.getId(), "template_" + System.currentTimeMillis());
}
TemplateInstance instance = instantiateFlowFromTemplate(tempGroup.getId(), templateId);
FlowSnippetDTO snippet = instance.getFlowSnippetDTO();
identifyNewlyCreatedControllerServiceReferences(instance);
tempGroup.setContents(snippet);
// now delete it
nifiRestClient.processGroups().delete(tempGroup);
cleanupControllerServices();
return tempGroup;
}
Aggregations