Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of the packages management #8680

Merged
merged 6 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pulsar-package-management/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ public interface PackagesManagement {
*
* @param storage
* the storage used to saving packages
* @return
*/
CompletableFuture<Void> initialize(PackagesStorage storage);
void initialize(PackagesStorage storage);

/**
* Get the metadata of a package.
Expand Down Expand Up @@ -94,7 +93,7 @@ public interface PackagesManagement {
* @return
* all the versions of the specified package
*/
CompletableFuture<List<PackageName>> list(PackageName packageName);
CompletableFuture<List<String>> list(PackageName packageName);

/**
* List all the packages with the type of a namespace.
Expand All @@ -103,7 +102,7 @@ public interface PackagesManagement {
* @param tenant the tenant name
* @param namespace the namespace name
* @return
* the packages under the specified namespace
* the packages name under the specified namespace
*/
CompletableFuture<List<PackageName>> list(PackageType type, String tenant, String namespace);
CompletableFuture<List<String>> list(PackageType type, String tenant, String namespace);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@

package org.apache.pulsar.packages.management.core.common;

import java.io.Serializable;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException.MetadataFormatException;

/**
* Package metadata.
Expand All @@ -36,10 +39,26 @@
@NoArgsConstructor
@Setter
@Getter
public class PackageMetadata {
public class PackageMetadata implements Serializable {
String description;
String contact;
long createTime;
long modificationTime;
Map<String, String> properties;

public static PackageMetadata fromBytes(byte[] bytes) throws MetadataFormatException {
try {
Object o = SerializationUtils.deserialize(bytes);
if (!(o instanceof PackageMetadata)) {
throw new MetadataFormatException("Unexpected metadata format");
}
return (PackageMetadata) o;
} catch (Exception e) {
throw new MetadataFormatException("Unexpected error", e);
}
}

public byte[] toBytes() {
return SerializationUtils.serialize(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* 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.exceptions;

/**
* Packages management related exceptions.
*/
public class PackagesManagementException extends Exception {
/**
* Constructs an {@code PackagesManagementException} with the specified cause.
*
* @param throwable
* The cause
*/
public PackagesManagementException(Throwable throwable) {
super(throwable);
}

/**
* Constructs an {@code PackagesManagementException} with the specified detail message.
*
* @param message
* The detail message
*/
public PackagesManagementException(String message) {
super(message);
}

/**
* Constructs an {@code PackagesManagementException} with the specified detail message and the cause.
*
* @param message
* The detail message
* @param throwable
* The cause
*/
public PackagesManagementException(String message, Throwable throwable) {
super(message, throwable);
}


public static class NotFoundException extends PackagesManagementException {
/**
* Constructs an {@code NotFoundException} with the specified cause.
*
* @param throwable
* The cause
*/
public NotFoundException(Throwable throwable) {
super(throwable);
}

/**
* Constructs an {@code NotFoundException} with the specified detail message.
*
* @param message
* The detail message
*/
public NotFoundException(String message) {
super(message);
}

/**
* Constructs an {@code NotFoundException} with the specified detail message and the cause.
*
* @param message
* The detail message
* @param throwable
* The cause
*/
public NotFoundException(String message, Throwable throwable) {
super(message, throwable);
}
}

public static class MetadataFormatException extends PackagesManagementException {
/**
* Constructs an {@code MetadataFormatException} with the specified detail message.
*
* @param message
* The detail message
*/
public MetadataFormatException(String message) {
super(message);
}

/**
* Constructs an {@code MetadataFormatException} with the specified detail message and the cause.
*
* @param message
* The detail message
* @param throwable
* The cause
*/
public MetadataFormatException(String message, Throwable throwable) {
super(message, throwable);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* 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.
*/

/**
* Exceptions of the packages management service thrown.
*/
package org.apache.pulsar.packages.management.core.exceptions;
Loading