Search in sources :

Example 6 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi by apache.

the class VersionedFlowsResult method writeSimpleResult.

@Override
protected void writeSimpleResult(PrintStream output) {
    if (versionedFlows.isEmpty()) {
        return;
    }
    final Table table = new Table.Builder().column("#", 3, 3, false).column("Name", 20, 36, true).column("Id", 36, 36, false).column("Description", 11, 40, true).build();
    for (int i = 0; i < versionedFlows.size(); ++i) {
        final VersionedFlow flow = versionedFlows.get(i);
        table.addRow(String.valueOf(i + 1), flow.getName(), flow.getIdentifier(), flow.getDescription());
    }
    final TableWriter tableWriter = new DynamicTableWriter();
    tableWriter.write(table, output);
}
Also used : Table(org.apache.nifi.toolkit.cli.impl.result.writer.Table) DynamicTableWriter(org.apache.nifi.toolkit.cli.impl.result.writer.DynamicTableWriter) TableWriter(org.apache.nifi.toolkit.cli.impl.result.writer.TableWriter) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) DynamicTableWriter(org.apache.nifi.toolkit.cli.impl.result.writer.DynamicTableWriter)

Example 7 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi by apache.

the class TestVersionedFlowsResult method setup.

@Before
public void setup() {
    this.outputStream = new ByteArrayOutputStream();
    this.printStream = new PrintStream(outputStream, true);
    final VersionedFlow f1 = new VersionedFlow();
    f1.setName("Flow 1");
    f1.setDescription("This is flow 1");
    f1.setIdentifier(UUID.fromString("ea752054-22c6-4fc0-b851-967d9a3837cb").toString());
    f1.setBucketIdentifier("b1");
    f1.setBucketName("Bucket 1");
    final VersionedFlow f2 = new VersionedFlow();
    f2.setName("Flow 2");
    f2.setDescription(null);
    f2.setIdentifier(UUID.fromString("ddf5f289-7502-46df-9798-4b0457c1816b").toString());
    f2.setBucketIdentifier("b2");
    f2.setBucketName("Bucket 2");
    this.flows = new ArrayList<>();
    flows.add(f1);
    flows.add(f2);
}
Also used : PrintStream(java.io.PrintStream) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 8 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi by apache.

the class StandardProcessGroup method synchronizeWithFlowRegistry.

@Override
public void synchronizeWithFlowRegistry(final FlowRegistryClient flowRegistryClient) {
    final StandardVersionControlInformation vci = versionControlInfo.get();
    if (vci == null) {
        return;
    }
    final String registryId = vci.getRegistryIdentifier();
    final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(registryId);
    if (flowRegistry == null) {
        final String message = String.format("Unable to synchronize Process Group with Flow Registry because Process Group was placed under Version Control using Flow Registry " + "with identifier %s but cannot find any Flow Registry with this identifier", registryId);
        versionControlFields.setSyncFailureExplanation(message);
        LOG.error("Unable to synchronize {} with Flow Registry because Process Group was placed under Version Control using Flow Registry " + "with identifier {} but cannot find any Flow Registry with this identifier", this, registryId);
        return;
    }
    final VersionedProcessGroup snapshot = vci.getFlowSnapshot();
    if (snapshot == null) {
        // This allows us to know whether or not the flow has been modified since it was last synced with the Flow Registry.
        try {
            final VersionedFlowSnapshot registrySnapshot = flowRegistry.getFlowContents(vci.getBucketIdentifier(), vci.getFlowIdentifier(), vci.getVersion(), false);
            final VersionedProcessGroup registryFlow = registrySnapshot.getFlowContents();
            vci.setFlowSnapshot(registryFlow);
        } catch (final IOException | NiFiRegistryException e) {
            final String message = String.format("Failed to synchronize Process Group with Flow Registry because could not retrieve version %s of flow with identifier %s in bucket %s", vci.getVersion(), vci.getFlowIdentifier(), vci.getBucketIdentifier());
            versionControlFields.setSyncFailureExplanation(message);
            LOG.error("Failed to synchronize {} with Flow Registry because could not retrieve version {} of flow with identifier {} in bucket {}", this, vci.getVersion(), vci.getFlowIdentifier(), vci.getBucketIdentifier(), e);
            return;
        }
    }
    try {
        final VersionedFlow versionedFlow = flowRegistry.getVersionedFlow(vci.getBucketIdentifier(), vci.getFlowIdentifier());
        final int latestVersion = (int) versionedFlow.getVersionCount();
        vci.setBucketName(versionedFlow.getBucketName());
        vci.setFlowName(versionedFlow.getName());
        vci.setFlowDescription(versionedFlow.getDescription());
        vci.setRegistryName(flowRegistry.getName());
        if (latestVersion == vci.getVersion()) {
            LOG.debug("{} is currently at the most recent version ({}) of the flow that is under Version Control", this, latestVersion);
            versionControlFields.setStale(false);
        } else {
            LOG.info("{} is not the most recent version of the flow that is under Version Control; current version is {}; most recent version is {}", new Object[] { this, vci.getVersion(), latestVersion });
            versionControlFields.setStale(true);
        }
        versionControlFields.setSyncFailureExplanation(null);
    } catch (final IOException | NiFiRegistryException e) {
        final String message = String.format("Failed to synchronize Process Group with Flow Registry : " + e.getMessage());
        versionControlFields.setSyncFailureExplanation(message);
        LOG.error("Failed to synchronize {} with Flow Registry because could not determine the most recent version of the Flow in the Flow Registry", this, e);
    }
}
Also used : StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) IOException(java.io.IOException) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException)

Example 9 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class BucketItemDeserializer method deserialize.

@Override
public BucketItem[] deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final JsonNode arrayNode = jsonParser.getCodec().readTree(jsonParser);
    final List<BucketItem> bucketItems = new ArrayList<>();
    final Iterator<JsonNode> nodeIter = arrayNode.elements();
    while (nodeIter.hasNext()) {
        final JsonNode node = nodeIter.next();
        final String type = node.get("type").asText();
        if (StringUtils.isBlank(type)) {
            throw new IllegalStateException("BucketItem type cannot be null or blank");
        }
        final BucketItemType bucketItemType;
        try {
            bucketItemType = BucketItemType.valueOf(type);
        } catch (Exception e) {
            throw new IllegalStateException("Unknown type for BucketItem: " + type, e);
        }
        switch(bucketItemType) {
            case Flow:
                final VersionedFlow versionedFlow = jsonParser.getCodec().treeToValue(node, VersionedFlow.class);
                bucketItems.add(versionedFlow);
                break;
            default:
                throw new IllegalStateException("Unknown type for BucketItem");
        }
    }
    return bucketItems.toArray(new BucketItem[bucketItems.size()]);
}
Also used : ArrayList(java.util.ArrayList) BucketItemType(org.apache.nifi.registry.bucket.BucketItemType) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) BucketItem(org.apache.nifi.registry.bucket.BucketItem) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 10 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class JerseyFlowClient method getByBucket.

@Override
public List<VersionedFlow> getByBucket(final String bucketId) throws NiFiRegistryException, IOException {
    if (StringUtils.isBlank(bucketId)) {
        throw new IllegalArgumentException("Bucket Identifier cannot be blank");
    }
    return executeAction("Error getting flows for bucket", () -> {
        WebTarget target = bucketFlowsTarget;
        target = target.resolveTemplate("bucketId", bucketId);
        final VersionedFlow[] versionedFlows = getRequestBuilder(target).get(VersionedFlow[].class);
        return versionedFlows == null ? Collections.emptyList() : Arrays.asList(versionedFlows);
    });
}
Also used : VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) WebTarget(javax.ws.rs.client.WebTarget)

Aggregations

VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)46 Test (org.junit.Test)19 Bucket (org.apache.nifi.registry.bucket.Bucket)12 BucketEntity (org.apache.nifi.registry.db.entity.BucketEntity)11 FlowEntity (org.apache.nifi.registry.db.entity.FlowEntity)11 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)11 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)10 Date (java.util.Date)9 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)8 ApiOperation (io.swagger.annotations.ApiOperation)7 ApiResponses (io.swagger.annotations.ApiResponses)7 Consumes (javax.ws.rs.Consumes)7 Produces (javax.ws.rs.Produces)7 ArrayList (java.util.ArrayList)6 Path (javax.ws.rs.Path)6 IOException (java.io.IOException)5 FlowClient (org.apache.nifi.registry.client.FlowClient)5 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)5 TreeSet (java.util.TreeSet)3 Response (javax.ws.rs.core.Response)3