@Override public ResolvedReference resolve(final CommandOption option, final Integer position) { final VersionedFlow versionedFlow = backRefs.get(position); if (versionedFlow != null) { if (option != null && option == CommandOption.BUCKET_ID) { return new ResolvedReference(option, position, versionedFlow.getBucketName(), versionedFlow.getBucketIdentifier()); } else { return new ResolvedReference(option, position, versionedFlow.getName(), versionedFlow.getIdentifier()); } } else { return null; } }
@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); }
@Override public OkResult doExecute(final NiFiRegistryClient client, final Properties properties) throws IOException, NiFiRegistryException, ParseException { final String flowId = getRequiredArg(properties, CommandOption.FLOW_ID); final boolean forceDelete = properties.containsKey(CommandOption.FORCE.getLongName()); final FlowClient flowClient = client.getFlowClient(); final VersionedFlow versionedFlow = flowClient.get(flowId); final FlowSnapshotClient flowSnapshotClient = client.getFlowSnapshotClient(); final List<VersionedFlowSnapshotMetadata> snapshotMetadata = flowSnapshotClient.getSnapshotMetadata(flowId); if (snapshotMetadata != null && snapshotMetadata.size() > 0 && !forceDelete) { throw new NiFiRegistryException("Flow has versions, use --" + CommandOption.FORCE.getLongName() + " to delete"); } else { flowClient.delete(versionedFlow.getBucketIdentifier(), versionedFlow.getIdentifier()); return new OkResult(getContext().isInteractive()); } } }
vci.setBucketName(bucket.getName()); vci.setFlowDescription(flow.getDescription()); vci.setFlowId(flow.getIdentifier()); vci.setFlowName(flow.getName()); vci.setGroupId(groupId);
@Override public VersionedFlowSnapshot registerVersionedFlowSnapshot(final VersionedFlow flow, final VersionedProcessGroup snapshot, final String comments, final int expectedVersion, final NiFiUser user) throws IOException, NiFiRegistryException { final FlowSnapshotClient snapshotClient = getFlowSnapshotClient(user); final VersionedFlowSnapshot versionedFlowSnapshot = new VersionedFlowSnapshot(); versionedFlowSnapshot.setFlowContents(snapshot); final VersionedFlowSnapshotMetadata metadata = new VersionedFlowSnapshotMetadata(); metadata.setBucketIdentifier(flow.getBucketIdentifier()); metadata.setFlowIdentifier(flow.getIdentifier()); metadata.setAuthor(getIdentity(user)); metadata.setTimestamp(System.currentTimeMillis()); metadata.setVersion(expectedVersion); metadata.setComments(comments); versionedFlowSnapshot.setSnapshotMetadata(metadata); return snapshotClient.create(versionedFlowSnapshot); }
private VersionedFlowEntity createVersionedFlowEntity(final String registryId, final VersionedFlow versionedFlow) { if (versionedFlow == null) { return null; } final VersionedFlowDTO dto = new VersionedFlowDTO(); dto.setRegistryId(registryId); dto.setBucketId(versionedFlow.getBucketIdentifier()); dto.setFlowId(versionedFlow.getIdentifier()); dto.setFlowName(versionedFlow.getName()); dto.setDescription(versionedFlow.getDescription()); final VersionedFlowEntity entity = new VersionedFlowEntity(); entity.setVersionedFlow(dto); return entity; }
@Override public StringResult doExecute(final NiFiRegistryClient client, final Properties properties) throws ParseException, IOException, NiFiRegistryException { final String bucketId = getRequiredArg(properties, CommandOption.BUCKET_ID); final String flowName = getRequiredArg(properties, CommandOption.FLOW_NAME); final String flowDesc = getArg(properties, CommandOption.FLOW_DESC); final VersionedFlow flow = new VersionedFlow(); flow.setName(flowName); flow.setDescription(flowDesc); flow.setBucketIdentifier(bucketId); final FlowClient flowClient = client.getFlowClient(); final VersionedFlow createdFlow = flowClient.create(flow); return new StringResult(createdFlow.getIdentifier(), getContext().isInteractive()); } }
final List<Integer> srcVersions = getVersions(srcClient, srcFlow.getIdentifier()); final List<Integer> destVersions = getVersions(client, destFlow.getIdentifier());
final List<Integer> destVersions = getVersions(client, destFlow.getIdentifier()); final Integer destFlowVersion = destVersions.isEmpty() ? 1 : destVersions.get(0) + 1;
vci.setBucketId(bucket.getIdentifier()); vci.setBucketName(bucket.getName()); vci.setFlowId(flow.getIdentifier()); vci.setFlowName(flow.getName()); vci.setFlowDescription(flow.getDescription());
if (StringUtils.isBlank(versionedFlow.getIdentifier())) { throw new IllegalArgumentException("Versioned flow identifier cannot be null or blank"); final FlowEntity existingFlow = metadataService.getFlowByIdWithSnapshotCounts(versionedFlow.getIdentifier()); if (existingFlow == null) { LOGGER.warn("The specified flow id [{}] does not exist.", versionedFlow.getIdentifier()); throw new ResourceNotFoundException("The specified flow ID does not exist in this bucket.");
public static FlowEntity map(final VersionedFlow versionedFlow) { final FlowEntity flowEntity = new FlowEntity(); flowEntity.setId(versionedFlow.getIdentifier()); flowEntity.setName(versionedFlow.getName()); flowEntity.setDescription(versionedFlow.getDescription()); flowEntity.setCreated(new Date(versionedFlow.getCreatedTimestamp())); flowEntity.setModified(new Date(versionedFlow.getModifiedTimestamp())); flowEntity.setType(BucketItemEntityType.FLOW); return flowEntity; }
public static Event flowUpdated(final VersionedFlow versionedFlow) { return new StandardEvent.Builder() .eventType(EventType.UPDATE_FLOW) .addField(EventFieldName.BUCKET_ID, versionedFlow.getBucketIdentifier()) .addField(EventFieldName.FLOW_ID, versionedFlow.getIdentifier()) .addField(EventFieldName.USER, NiFiUserUtils.getNiFiUserIdentity()) .build(); }
public static Event flowDeleted(final VersionedFlow versionedFlow) { return new StandardEvent.Builder() .eventType(EventType.DELETE_FLOW) .addField(EventFieldName.BUCKET_ID, versionedFlow.getBucketIdentifier()) .addField(EventFieldName.FLOW_ID, versionedFlow.getIdentifier()) .addField(EventFieldName.USER, NiFiUserUtils.getNiFiUserIdentity()) .build(); }
public static Event flowCreated(final VersionedFlow versionedFlow) { return new StandardEvent.Builder() .eventType(EventType.CREATE_FLOW) .addField(EventFieldName.BUCKET_ID, versionedFlow.getBucketIdentifier()) .addField(EventFieldName.FLOW_ID, versionedFlow.getIdentifier()) .addField(EventFieldName.USER, NiFiUserUtils.getNiFiUserIdentity()) .build(); }