Search in sources :

Example 16 with NifiComponentNotFoundException

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

Example 17 with NifiComponentNotFoundException

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);
    }
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Nonnull(javax.annotation.Nonnull)

Example 18 with NifiComponentNotFoundException

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

Example 19 with NifiComponentNotFoundException

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;
}
Also used : Iterables(com.google.common.collect.Iterables) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) LoggerFactory(org.slf4j.LoggerFactory) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) NiFiAllowableValue(com.thinkbiganalytics.nifi.rest.model.NiFiAllowableValue) Lists(com.google.common.collect.Lists) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) NiFiObjectCache(com.thinkbiganalytics.nifi.rest.NiFiObjectCache) NifiPropertyUtil(com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil) Map(java.util.Map) NiFiRestClient(com.thinkbiganalytics.nifi.rest.client.NiFiRestClient) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) Nonnull(javax.annotation.Nonnull) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) Nullable(javax.annotation.Nullable) NifiTemplateNameUtil(com.thinkbiganalytics.nifi.rest.support.NifiTemplateNameUtil) Logger(org.slf4j.Logger) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Set(java.util.Set) ComparisonChain(com.google.common.collect.ComparisonChain) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) List(java.util.List) Predicate(com.google.common.base.Predicate) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) Comparator(java.util.Comparator) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) NiFiRestClient(com.thinkbiganalytics.nifi.rest.client.NiFiRestClient) HashMap(java.util.HashMap) Nonnull(javax.annotation.Nonnull)

Example 20 with NifiComponentNotFoundException

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;
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Aggregations

NifiComponentNotFoundException (com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)22 Nonnull (javax.annotation.Nonnull)10 NotFoundException (javax.ws.rs.NotFoundException)10 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)10 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)6 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)6 HashMap (java.util.HashMap)5 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)5 PortEntity (org.apache.nifi.web.api.entity.PortEntity)5 NifiClientRuntimeException (com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)4 NifiVisitableProcessGroup (com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup)4 LegacyNifiRestClient (com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient)3 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)3 NifiConstants (com.thinkbiganalytics.nifi.rest.support.NifiConstants)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Iterables (com.google.common.collect.Iterables)2 ReusableTemplateConnectionInfo (com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo)2 NifiPropertyUtil (com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil)2 HashSet (java.util.HashSet)2