forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the packages management interface API (apache#8669)
* Introduce the packages management interface API --- *Motivation* Implementation of the PIP-50. This PR introduces the package management APIs and storage APIs. The related implement will in the next PR. *Modifications* - Add package management APIs - Add package storage APIs - Introduce the package type, name, and metadata struct. * Remove unused the dependency
- Loading branch information
Showing
13 changed files
with
826 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>pulsar-package-management</artifactId> | ||
<groupId>org.apache.pulsar</groupId> | ||
<version>2.7.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>core</artifactId> | ||
<name>Apache Pulsar :: Package Management :: Core</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
109 changes: 109 additions & 0 deletions
109
...ent/core/src/main/java/org/apache/pulsar/packages/management/core/PackagesManagement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* 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.pulsar.packages.management.core; | ||
|
||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.apache.pulsar.packages.management.core.common.PackageMetadata; | ||
import org.apache.pulsar.packages.management.core.common.PackageName; | ||
import org.apache.pulsar.packages.management.core.common.PackageType; | ||
|
||
/** | ||
* PackagesManagement provides a way to manage the packages of function, sink, and source. | ||
*/ | ||
public interface PackagesManagement { | ||
/** | ||
* Initialize the packages management service with the given storage. | ||
* | ||
* @param storage | ||
* the storage used to saving packages | ||
* @return | ||
*/ | ||
CompletableFuture<Void> initialize(PackagesStorage storage); | ||
|
||
/** | ||
* Get the metadata of a package. | ||
* | ||
* @param packageName package name | ||
* @return | ||
*/ | ||
CompletableFuture<PackageMetadata> getMeta(PackageName packageName); | ||
|
||
/** | ||
* Update the metadata of a package. | ||
* | ||
* @param packageName package name | ||
* @param metadata | ||
* @return | ||
*/ | ||
CompletableFuture<Void> updateMeta(PackageName packageName, PackageMetadata metadata); | ||
|
||
/** | ||
* Download a package of a given version to a given path. | ||
* | ||
* @param packageName package name | ||
* @param outputStream | ||
* @return | ||
*/ | ||
CompletableFuture<Void> download(PackageName packageName, OutputStream outputStream); | ||
|
||
/** | ||
* Upload a package of a given version from a given path. | ||
* | ||
* @param packageName package name | ||
* @param metadata metadata of a package | ||
* @param inputStream | ||
* @return | ||
*/ | ||
CompletableFuture<Void> upload(PackageName packageName, PackageMetadata metadata, InputStream inputStream); | ||
|
||
/** | ||
* Delete a package. | ||
* It will delete all versions of a package if the version is not specified. | ||
* Otherwise it will delete the specified version package. | ||
* | ||
* @param packageName package name | ||
* type://tenant/namespace/name@version is delete a given version of the package | ||
* type://tenant/namespace/name is delete all versions of the package | ||
* @return | ||
*/ | ||
CompletableFuture<Void> delete(PackageName packageName); | ||
|
||
/** | ||
* List all the versions of a package. | ||
* | ||
* @param packageName package name without version | ||
* @return | ||
* all the versions of the specified package | ||
*/ | ||
CompletableFuture<List<PackageName>> list(PackageName packageName); | ||
|
||
/** | ||
* List all the packages with the type of a namespace. | ||
* | ||
* @param type the package type | ||
* @param tenant the tenant name | ||
* @param namespace the namespace name | ||
* @return | ||
* the packages under the specified namespace | ||
*/ | ||
CompletableFuture<List<PackageName>> list(PackageType type, String tenant, String namespace); | ||
} |
82 changes: 82 additions & 0 deletions
82
...gement/core/src/main/java/org/apache/pulsar/packages/management/core/PackagesStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* 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.pulsar.packages.management.core; | ||
|
||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public interface PackagesStorage { | ||
/** | ||
* Write a input stream to a path. | ||
* | ||
* @param path | ||
* file path | ||
* @param inputStream | ||
* the input file stream | ||
* @return | ||
*/ | ||
CompletableFuture<Void> writeAsync(String path, InputStream inputStream); | ||
|
||
/** | ||
* Read a file to a output stream. | ||
* | ||
* @param path | ||
* file path | ||
* @param outputStream | ||
* the output file stream | ||
* @return | ||
*/ | ||
CompletableFuture<Void> readAsync(String path, OutputStream outputStream); | ||
|
||
/** | ||
* Delete a file. | ||
* | ||
* @param path | ||
* file path | ||
* @return | ||
*/ | ||
CompletableFuture<Void> deleteAsync(String path); | ||
|
||
/** | ||
* List all the file under a path. | ||
* | ||
* @param path | ||
* file path | ||
* @return | ||
*/ | ||
CompletableFuture<List<String>> listAsync(String path); | ||
|
||
/** | ||
* Check the file is or not exists. | ||
* | ||
* @param path | ||
* file path | ||
* @return | ||
*/ | ||
CompletableFuture<Boolean> existAsync(String path); | ||
|
||
/** | ||
* Close storage asynchronously. | ||
* | ||
* @return | ||
*/ | ||
CompletableFuture<Void> closeAsync(); | ||
} |
43 changes: 43 additions & 0 deletions
43
...rc/main/java/org/apache/pulsar/packages/management/core/PackagesStorageConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* 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.pulsar.packages.management.core; | ||
|
||
/** | ||
* Packages storage configuration is used to set and get the storage related configuration values. | ||
*/ | ||
public interface PackagesStorageConfiguration { | ||
/** | ||
* Get a property with the key. | ||
* | ||
* @param key | ||
* property key | ||
* @return the value | ||
*/ | ||
Object getProperty(String key); | ||
|
||
/** | ||
* Set a property with the key. | ||
* | ||
* @param key | ||
* property key | ||
* @param value | ||
* property value | ||
*/ | ||
void setProperty(String key, Object value); | ||
} |
55 changes: 55 additions & 0 deletions
55
...ore/src/main/java/org/apache/pulsar/packages/management/core/PackagesStorageProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* 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.pulsar.packages.management.core; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import java.io.IOException; | ||
|
||
/** | ||
* The provider provides a generic method to get a storage provider. | ||
*/ | ||
public interface PackagesStorageProvider { | ||
/** | ||
* Construct a provider from the provided class. | ||
* | ||
* @param providerClassName the provider class name | ||
* @return an instance of package storage provider | ||
* @throws IOException | ||
*/ | ||
static PackagesStorageProvider newProvider(String providerClassName) throws IOException { | ||
Class<?> providerClass; | ||
try { | ||
providerClass = Class.forName(providerClassName); | ||
Object obj = providerClass.newInstance(); | ||
checkArgument(obj instanceof PackagesStorageProvider, | ||
"The package storage provider has to be an instance of " + PackagesStorageProvider.class.getName()); | ||
return (PackagesStorageProvider) obj; | ||
} catch (Exception e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Get a storage with the configuration. | ||
* | ||
* @param config storage configuration | ||
* @return | ||
*/ | ||
PackagesStorage getStorage(PackagesStorageConfiguration config); | ||
} |
Oops, something went wrong.