This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #323 from erandacr/cli-output-formatting
Add queue consumer admin operations
- Loading branch information
Showing
14 changed files
with
321 additions
and
6 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
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
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
103 changes: 103 additions & 0 deletions
103
...ent/src/main/java/io/ballerina/messaging/broker/client/cmd/impl/list/ListConsumerCmd.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,103 @@ | ||
/* | ||
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. 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 io.ballerina.messaging.broker.client.cmd.impl.list; | ||
|
||
import com.beust.jcommander.Parameter; | ||
import com.beust.jcommander.Parameters; | ||
import com.google.gson.Gson; | ||
import io.ballerina.messaging.broker.client.http.HttpClient; | ||
import io.ballerina.messaging.broker.client.http.HttpRequest; | ||
import io.ballerina.messaging.broker.client.http.HttpResponse; | ||
import io.ballerina.messaging.broker.client.output.ResponseFormatter; | ||
import io.ballerina.messaging.broker.client.output.TableFormatter; | ||
import io.ballerina.messaging.broker.client.resources.Configuration; | ||
import io.ballerina.messaging.broker.client.resources.Consumer; | ||
import io.ballerina.messaging.broker.client.utils.Constants; | ||
import io.ballerina.messaging.broker.client.utils.Utils; | ||
|
||
import java.net.HttpURLConnection; | ||
|
||
import static io.ballerina.messaging.broker.client.utils.Constants.BROKER_ERROR_MSG; | ||
import static io.ballerina.messaging.broker.client.utils.Constants.HTTP_GET; | ||
|
||
/** | ||
* Command representing MB consumer information retrieval. | ||
*/ | ||
@Parameters(commandDescription = "List consumers in a Broker queue") | ||
public class ListConsumerCmd extends ListCmd { | ||
|
||
@Parameter(names = { "--all", "-a" }, | ||
description = "return info on all consumer of the queue") | ||
private boolean all; | ||
|
||
@Parameter(names = { "--consumer", "-c" }, | ||
description = "id of the consumer which info needs to be retrieved") | ||
private String consumerId = ""; | ||
|
||
@Parameter(description = "name of the queue", | ||
required = true) | ||
private String queueName = ""; | ||
|
||
public ListConsumerCmd(String rootCommand) { | ||
super(rootCommand); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
if (help) { | ||
processHelpLogs(); | ||
return; | ||
} | ||
|
||
Configuration configuration = Utils.readConfigurationFile(); | ||
HttpClient httpClient = new HttpClient(configuration); | ||
|
||
if (all) { | ||
consumerId = ""; | ||
} | ||
|
||
// do GET | ||
HttpRequest httpRequest = new HttpRequest( | ||
Constants.QUEUES_URL_PARAM + queueName + Constants.CONSUMERS_URL_PARAM + consumerId); | ||
HttpResponse response = httpClient.sendHttpRequest(httpRequest, HTTP_GET); | ||
|
||
// handle data processing | ||
ResponseFormatter responseFormatter = new TableFormatter(); | ||
|
||
if (response.getStatusCode() == HttpURLConnection.HTTP_OK) { | ||
Gson gson = new Gson(); | ||
Consumer[] consumers; | ||
if (consumerId.isEmpty()) { | ||
consumers = gson.fromJson(response.getPayload(), Consumer[].class); | ||
} else { | ||
consumers = new Consumer[] { gson.fromJson(response.getPayload(), Consumer.class) }; | ||
} | ||
responseFormatter.printConsumers(consumers); | ||
} else { | ||
ResponseFormatter.handleErrorResponse(buildResponseMessage(response, BROKER_ERROR_MSG)); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void appendUsage(StringBuilder out) { | ||
out.append("Usage:\n"); | ||
out.append(" " + rootCommand + " list consumer [queue-name] [flag]*\n"); | ||
} | ||
} |
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
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
60 changes: 60 additions & 0 deletions
60
...ker-cli-client/src/main/java/io/ballerina/messaging/broker/client/resources/Consumer.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,60 @@ | ||
/* | ||
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. 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 io.ballerina.messaging.broker.client.resources; | ||
|
||
/** | ||
* Representation of consumer in a broker queue. | ||
*/ | ||
public class Consumer { | ||
|
||
public static final String CONSUMER_ID = "id"; | ||
public static final String IS_EXCLUSIVE = "isExclusive"; | ||
public static final String FLOW_ENABLED = "flowEnabled"; | ||
|
||
private String queueName; | ||
|
||
private int id; | ||
|
||
private boolean isExclusive; | ||
|
||
private boolean flowEnabled; | ||
|
||
public Consumer(String queueName, int id, boolean isExclusive, boolean flowEnabled) { | ||
this.queueName = queueName; | ||
this.id = id; | ||
this.isExclusive = isExclusive; | ||
this.flowEnabled = flowEnabled; | ||
} | ||
|
||
public String getQueueName() { | ||
return queueName; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public boolean isExclusive() { | ||
return isExclusive; | ||
} | ||
|
||
public boolean isFlowEnabled() { | ||
return flowEnabled; | ||
} | ||
} |
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
Oops, something went wrong.