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