Skip to content

Commit

Permalink
NIFI-13105 Implemented FlowRegistryClient using GitHub for versioning
Browse files Browse the repository at this point in the history
This closes #8765

Signed-off-by: David Handermann <exceptionfactory@apache.org>
  • Loading branch information
bbende authored and exceptionfactory committed May 9, 2024
1 parent fe90baa commit 7cd1a30
Show file tree
Hide file tree
Showing 21 changed files with 1,817 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

/**
* <p>
Expand Down Expand Up @@ -146,7 +147,7 @@ default FlowRegistryBranch getDefaultBranch(final FlowRegistryClientConfiguratio
FlowRegistryBucket getBucket(FlowRegistryClientConfigurationContext context, BucketLocation bucketLocation) throws FlowRegistryException, IOException;

/**
* Registers the given RegisteredFlow into the the Flow Registry.
* Registers the given RegisteredFlow into the Flow Registry.
*
* @param context Configuration context.
* @param flow The RegisteredFlow to add to the Registry.
Expand Down Expand Up @@ -252,4 +253,15 @@ default FlowRegistryBranch getDefaultBranch(final FlowRegistryClientConfiguratio
* @throws IOException If there is issue with the communication between NiFi and the Flow Registry.
*/
Optional<String> getLatestVersion(FlowRegistryClientConfigurationContext context, FlowLocation flowLocation) throws FlowRegistryException, IOException;

/**
* Generates the id for registering a flow.
*
* @param flowName the name of the flow
* @return the generated id
*/
default String generateFlowId(final String flowName) {
return UUID.randomUUID().toString();
}

}
6 changes: 6 additions & 0 deletions nifi-assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,12 @@ language governing permissions and limitations under the License. -->
<version>2.0.0-SNAPSHOT</version>
<type>nar</type>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-github-nar</artifactId>
<version>2.0.0-SNAPSHOT</version>
<type>nar</type>
</dependency>
<!-- AspectJ library needed by the Java Agent used for native library loading (see bootstrap.conf) -->
<dependency>
<groupId>org.aspectj</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-github-bundle</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>nifi-github-extensions</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-utils</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jakarta-xmlbind-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>${github-api.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.nifi.github;

import org.apache.nifi.registry.flow.RegisteredFlowSnapshot;

import java.io.IOException;
import java.io.InputStream;

/**
* Serializer for flow snapshots.
*/
public interface FlowSnapshotSerializer {

String serialize(final RegisteredFlowSnapshot flowSnapshot) throws IOException;

RegisteredFlowSnapshot deserialize(final InputStream inputStream) throws IOException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.nifi.github;

/**
* Enumeration of authentication types for the GitHub client.
*/
public enum GitHubAuthenticationType {

NONE,
PERSONAL_ACCESS_TOKEN,
APP_INSTALLATION_TOKEN;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.nifi.github;

import java.util.Objects;

public class GitHubCreateContentRequest {

private final String branch;
private final String path;
private final String content;
private final String message;
private final String existingContentSha;

private GitHubCreateContentRequest(final Builder builder) {
this.branch = Objects.requireNonNull(builder.branch);
this.path = Objects.requireNonNull(builder.path);
this.content = Objects.requireNonNull(builder.content);
this.message = Objects.requireNonNull(builder.message);
// Will be null for create, and populated for update
this.existingContentSha = builder.existingContentSha;
}

public String getBranch() {
return branch;
}

public String getPath() {
return path;
}

public String getContent() {
return content;
}

public String getMessage() {
return message;
}

public String getExistingContentSha() {
return existingContentSha;
}

public static Builder builder() {
return new Builder();
}

public static final class Builder {
private String branch;
private String path;
private String content;
private String message;
private String existingContentSha;

public Builder branch(final String branch) {
this.branch = branch;
return this;
}

public Builder path(final String path) {
this.path = path;
return this;
}

public Builder content(final String content) {
this.content = content;
return this;
}

public Builder message(final String message) {
this.message = message;
return this;
}

public Builder existingContentSha(final String existingSha) {
this.existingContentSha = existingSha;
return this;
}

public GitHubCreateContentRequest build() {
return new GitHubCreateContentRequest(this);
}
}
}

0 comments on commit 7cd1a30

Please sign in to comment.