Search in sources :

Example 1 with StandardSnippet

use of org.apache.nifi.controller.StandardSnippet in project nifi by apache.

the class StandardSnippetDAO method updateSnippetComponents.

@Override
public Snippet updateSnippetComponents(final SnippetDTO snippetDTO) {
    // verify the action
    verifyUpdateSnippetComponent(snippetDTO);
    // find the snippet in question
    final StandardSnippet snippet = locateSnippet(snippetDTO.getId());
    // if the group is changing move it
    if (snippetDTO.getParentGroupId() != null && !snippet.getParentGroupId().equals(snippetDTO.getParentGroupId())) {
        final ProcessGroup currentProcessGroup = flowController.getGroup(snippet.getParentGroupId());
        if (currentProcessGroup == null) {
            throw new IllegalArgumentException("The current process group could not be found.");
        }
        final ProcessGroup newProcessGroup = flowController.getGroup(snippetDTO.getParentGroupId());
        if (newProcessGroup == null) {
            throw new IllegalArgumentException("The new process group could not be found.");
        }
        // move the snippet
        currentProcessGroup.move(snippet, newProcessGroup);
        // update its parent group id
        snippet.setParentGroupId(snippetDTO.getParentGroupId());
    }
    return snippet;
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) StandardSnippet(org.apache.nifi.controller.StandardSnippet)

Example 2 with StandardSnippet

use of org.apache.nifi.controller.StandardSnippet in project nifi by apache.

the class StandardSnippetDAO method dropSnippet.

@Override
public void dropSnippet(String snippetId) {
    // drop the snippet itself
    final StandardSnippet snippet = locateSnippet(snippetId);
    flowController.getSnippetManager().removeSnippet(snippet);
}
Also used : StandardSnippet(org.apache.nifi.controller.StandardSnippet)

Example 3 with StandardSnippet

use of org.apache.nifi.controller.StandardSnippet in project nifi by apache.

the class StandardSnippetDAO method createSnippet.

@Override
public Snippet createSnippet(final SnippetDTO snippetDTO) {
    // create the snippet request
    final StandardSnippet snippet = new StandardSnippet();
    snippet.setId(snippetDTO.getId());
    snippet.setParentGroupId(snippetDTO.getParentGroupId());
    snippet.addProcessors(mapDtoToRevision(snippetDTO.getProcessors()));
    snippet.addProcessGroups(mapDtoToRevision(snippetDTO.getProcessGroups()));
    snippet.addRemoteProcessGroups(mapDtoToRevision(snippetDTO.getRemoteProcessGroups()));
    snippet.addInputPorts(mapDtoToRevision(snippetDTO.getInputPorts()));
    snippet.addOutputPorts(mapDtoToRevision(snippetDTO.getOutputPorts()));
    snippet.addConnections(mapDtoToRevision(snippetDTO.getConnections()));
    snippet.addLabels(mapDtoToRevision(snippetDTO.getLabels()));
    snippet.addFunnels(mapDtoToRevision(snippetDTO.getFunnels()));
    // ensure this snippet isn't empty
    if (snippet.isEmpty()) {
        throw new IllegalArgumentException("Cannot create an empty snippet.");
    }
    // ensure the parent group exist
    final ProcessGroup processGroup = flowController.getGroup(snippet.getParentGroupId());
    if (processGroup == null) {
        throw new IllegalArgumentException("The specified parent process group could not be found.");
    }
    // store the snippet
    flowController.getSnippetManager().addSnippet(snippet);
    return snippet;
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) StandardSnippet(org.apache.nifi.controller.StandardSnippet)

Example 4 with StandardSnippet

use of org.apache.nifi.controller.StandardSnippet in project nifi by apache.

the class StandardSnippetDeserializer method deserialize.

public static StandardSnippet deserialize(final InputStream inStream) {
    try {
        JAXBContext context = JAXBContext.newInstance(StandardSnippet.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        XMLStreamReader xsr = XmlUtils.createSafeReader(inStream);
        JAXBElement<StandardSnippet> snippetElement = unmarshaller.unmarshal(xsr, StandardSnippet.class);
        return snippetElement.getValue();
    } catch (final JAXBException | XMLStreamException e) {
        throw new FlowSerializationException(e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) StandardSnippet(org.apache.nifi.controller.StandardSnippet)

Aggregations

StandardSnippet (org.apache.nifi.controller.StandardSnippet)4 ProcessGroup (org.apache.nifi.groups.ProcessGroup)2 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 FlowSerializationException (org.apache.nifi.controller.serialization.FlowSerializationException)1