Skip to content

Commit

Permalink
Introduce the packages management interface API (apache#8669)
Browse files Browse the repository at this point in the history
* 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
zymap authored Nov 25, 2020
1 parent b5b5c89 commit 8b15792
Show file tree
Hide file tree
Showing 13 changed files with 826 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,10 @@ flexible messaging model and an intuitive client API.</description>
<module>tests</module>
<module>pulsar-metadata</module>
<module>jclouds-shaded</module>

<!-- package management releated modules (begin) -->
<module>pulsar-package-management</module>
<!-- package management releated modules (end) -->
</modules>
</profile>

Expand Down Expand Up @@ -1675,6 +1679,10 @@ flexible messaging model and an intuitive client API.</description>
<!-- all these modules should be put at the end in this exact sequence -->
<module>distribution</module>
<module>pulsar-metadata</module>

<!-- package management releated modules (begin) -->
<module>pulsar-package-management</module>
<!-- package management releated modules (end) -->
</modules>
</profile>

Expand Down
46 changes: 46 additions & 0 deletions pulsar-package-management/core/pom.xml
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>
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);
}
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();
}
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);
}
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);
}
Loading

0 comments on commit 8b15792

Please sign in to comment.