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.
Package management client command (apache#8817)
--- Master Issue: apache#8676 *Motivation* Add commands for package management service in pulsar-admin tool. *Modifications* - Add commands for package management service
- Loading branch information
Showing
4 changed files
with
369 additions
and
1 deletion.
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
165 changes: 165 additions & 0 deletions
165
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdPackages.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,165 @@ | ||
/** | ||
* 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.admin.cli; | ||
|
||
import com.beust.jcommander.DynamicParameter; | ||
import com.beust.jcommander.Parameter; | ||
import com.beust.jcommander.Parameters; | ||
import org.apache.pulsar.client.admin.Packages; | ||
import org.apache.pulsar.client.admin.PulsarAdmin; | ||
import org.apache.pulsar.packages.management.core.common.PackageMetadata; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Commands for administering packages. | ||
*/ | ||
@Parameters(commandDescription = "Operations about packages") | ||
class CmdPackages extends CmdBase { | ||
|
||
private final Packages packages; | ||
|
||
CmdPackages(PulsarAdmin admin) { | ||
super("packages", admin); | ||
this.packages = admin.packages(); | ||
|
||
jcommander.addCommand("get-metadata", new GetMetadataCmd()); | ||
jcommander.addCommand("update-metadata", new UpdateMetadataCmd()); | ||
jcommander.addCommand("upload", new UploadCmd()); | ||
jcommander.addCommand("download", new DownloadCmd()); | ||
jcommander.addCommand("list", new ListPackagesCmd()); | ||
jcommander.addCommand("list-versions", new ListPackageVersionsCmd()); | ||
jcommander.addCommand("delete", new DeletePackageCmd()); | ||
} | ||
|
||
@Parameters(commandDescription = "Get a package metadata information.") | ||
private class GetMetadataCmd extends CliCommand { | ||
@Parameter(description = "type://tenant/namespace/packageName@version", required = true) | ||
private String packageName; | ||
|
||
@Override | ||
void run() throws Exception { | ||
print(packages.getMetadata(packageName)); | ||
} | ||
} | ||
|
||
@Parameters(commandDescription = "Update a package metadata information.") | ||
private class UpdateMetadataCmd extends CliCommand { | ||
@Parameter(description = "type://tenant/namespace/packageName@version", required = true) | ||
private String packageName; | ||
|
||
@Parameter(names = "--description", description= "descriptions of a package", required = true) | ||
private String description; | ||
|
||
@Parameter(names = "--contact", description = "contact info of a package") | ||
private String contact; | ||
|
||
@DynamicParameter(names = {"--properties", "-P"}, description ="external information of a package") | ||
private Map<String, String> properties = new HashMap<>(); | ||
|
||
@Override | ||
void run() throws Exception { | ||
packages.updateMetadata(packageName, PackageMetadata.builder() | ||
.description(description).contact(contact).properties(properties).build()); | ||
print(String.format("The metadata of the package '%s' updated successfully", packageName)); | ||
} | ||
} | ||
|
||
@Parameters(commandDescription = "Upload a package") | ||
private class UploadCmd extends CliCommand { | ||
@Parameter(description = "type://tenant/namespace/packageName@version", required = true) | ||
private String packageName; | ||
|
||
@Parameter(names = "--description", description= "descriptions of a package", required = true) | ||
private String description; | ||
|
||
@Parameter(names = "--contact", description = "contact information of a package") | ||
private String contact; | ||
|
||
@DynamicParameter(names = {"--properties", "-P"}, description ="external infromations of a package") | ||
private Map<String, String> properties = new HashMap<>(); | ||
|
||
@Parameter(names = "--path", description = "descriptions of a package", required = true) | ||
private String path; | ||
|
||
@Override | ||
void run() throws Exception { | ||
PackageMetadata metadata = PackageMetadata.builder() | ||
.description(description) | ||
.contact(contact) | ||
.properties(properties).build(); | ||
packages.upload(metadata, packageName, path); | ||
print(String.format("The package '%s' uploaded from path '%s' successfully", packageName, path)); | ||
} | ||
} | ||
|
||
@Parameters(commandDescription = "Download a package") | ||
private class DownloadCmd extends CliCommand { | ||
@Parameter(description = "type://tenant/namespace/packageName@version", required = true) | ||
private String packageName; | ||
|
||
@Parameter(names = "--path", description = "download destiny path of the package", required = true) | ||
private String path; | ||
|
||
@Override | ||
void run() throws Exception { | ||
packages.download(packageName, path); | ||
print(String.format("The package '%s' downloaded to path '%s' successfully", packageName, path)); | ||
} | ||
} | ||
|
||
@Parameters(commandDescription = "List all versions of the given package") | ||
private class ListPackageVersionsCmd extends CliCommand { | ||
@Parameter(description = "the package name you want to query, don't need to specify the package version.\n" + | ||
"type://tenant/namespace/packageName", required = true) | ||
private String packageName; | ||
|
||
@Override | ||
void run() throws Exception { | ||
print(packages.listPackageVersions(packageName).toString()); | ||
} | ||
} | ||
|
||
@Parameters(commandDescription = "List all packages with given type in the specified namespace") | ||
private class ListPackagesCmd extends CliCommand { | ||
@Parameter(names = "--type", description = "type of the package", required = true) | ||
private String type; | ||
|
||
@Parameter(description = "namespace of the package", required = true) | ||
private String namespace; | ||
|
||
@Override | ||
void run() throws Exception { | ||
print(packages.listPackages(type, namespace)); | ||
} | ||
} | ||
|
||
@Parameters(commandDescription = "Delete a package") | ||
private class DeletePackageCmd extends CliCommand{ | ||
@Parameter(description = "type://tenant/namespace/packageName@version", required = true) | ||
private String packageName; | ||
|
||
@Override | ||
void run() throws Exception { | ||
packages.delete(packageName); | ||
print(String.format("The package '%s' deleted successfully", packageName)); | ||
} | ||
} | ||
} |
Oops, something went wrong.