You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2014/10/11 15:27:56 UTC
[3/3] git commit: Refactoring CLI commands with a proper naming
convention
Refactoring CLI commands with a proper naming convention
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c9df250a
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c9df250a
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c9df250a
Branch: refs/heads/container-autoscaling
Commit: c9df250a1a08563f8ae4064156dd2570bf2bb6b8
Parents: 70a9cca
Author: Imesh Gunaratne <im...@apache.org>
Authored: Sat Oct 11 18:57:40 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sat Oct 11 18:57:40 2014 +0530
----------------------------------------------------------------------
.../apache/stratos/cli/CommandLineService.java | 12 +-
.../java/org/apache/stratos/cli/RestClient.java | 6 +-
.../stratos/cli/RestCommandLineService.java | 125 ++++----
.../apache/stratos/cli/StratosApplication.java | 30 +-
.../cli/commands/ActivateTenantCommand.java | 4 +-
.../cli/commands/AddDomainMappingCommand.java | 6 +-
.../stratos/cli/commands/AddTenantCommand.java | 8 +-
.../stratos/cli/commands/AddUserCommand.java | 8 +-
.../cli/commands/AutoscalePolicyCommand.java | 66 ----
.../AutoscalingPolicyDeploymentCommand.java | 138 ---------
.../commands/CartridgeDeploymentCommand.java | 140 ---------
.../cli/commands/DeactivateTenantCommand.java | 4 +-
.../cli/commands/DeleteTenantCommand.java | 4 +-
.../stratos/cli/commands/DeleteUserCommand.java | 4 +-
.../DeployAutoscalingPolicyCommand.java | 138 +++++++++
.../cli/commands/DeployCartridgeCommand.java | 140 +++++++++
.../commands/DeployDeploymentPolicyCommand.java | 138 +++++++++
.../commands/DeployKubernetesGroupCommand.java | 16 +-
.../commands/DeployKubernetesHostCommand.java | 16 +-
.../cli/commands/DeployPartitionCommand.java | 138 +++++++++
.../cli/commands/DeployServiceCommand.java | 139 +++++++++
.../DeployServiceDeploymentCommand.java | 139 ---------
.../cli/commands/DeploymentPolicyCommand.java | 66 ----
.../DeploymentPolicyDeploymentCommand.java | 138 ---------
.../DescribeAutoScalingPolicyCommand.java | 4 +-
.../cli/commands/DescribeCartridgeCommand.java | 4 +-
.../DescribeDeploymentPolicyCommand.java | 4 +-
.../cli/commands/DescribePartitionCommand.java | 4 +-
.../stratos/cli/commands/ExitCommand.java | 9 +-
.../stratos/cli/commands/HelpCommand.java | 6 +-
.../stratos/cli/commands/InfoCommand.java | 4 +-
.../stratos/cli/commands/ListAllTenants.java | 4 +-
.../stratos/cli/commands/ListAllUsers.java | 4 +-
.../commands/ListAutoscalePolicyCommand.java | 66 ++++
.../ListCartridgeSubscriptionsCommand.java | 95 ++++++
.../cli/commands/ListCartridgesCommand.java | 4 +-
.../cli/commands/ListDeployServiceCommand.java | 4 +-
.../commands/ListDeploymentPolicyCommand.java | 66 ++++
.../commands/ListKubernetesGroupsCommand.java | 4 +-
.../commands/ListKubernetesHostsCommand.java | 4 +-
.../stratos/cli/commands/ListMemberCommand.java | 10 +-
.../cli/commands/ListPartitionCommand.java | 65 ++++
.../ListSubscribedCartridgesCommand.java | 10 +-
.../stratos/cli/commands/PartitionCommand.java | 65 ----
.../commands/PartitionDeploymentCommand.java | 138 ---------
.../stratos/cli/commands/PoliciesCommand.java | 71 -----
.../commands/RemoveDomainMappingCommand.java | 75 -----
.../cli/commands/SubscribeCartridgeCommand.java | 307 ++++++++++++++++++
.../stratos/cli/commands/SubscribeCommand.java | 310 -------------------
.../SubscribedCartridgeInfoCommand.java | 101 ------
.../stratos/cli/commands/SyncCommand.java | 13 +-
.../UnDeployKubernetesGroupCommand.java | 6 +-
.../UndeployCartridgeDefinitionCommand.java | 4 +-
.../commands/UndeployKubernetesHostCommand.java | 4 +-
.../UndeployServiceDefinitionCommand.java | 4 +-
.../cli/commands/UnsubscribeCommand.java | 10 +-
.../apache/stratos/cli/utils/CliConstants.java | 4 +-
.../org/apache/stratos/cli/utils/CliUtils.java | 147 +++++++++
.../stratos/cli/utils/CommandLineUtils.java | 147 ---------
59 files changed, 1616 insertions(+), 1784 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
index 3939a4d..efc7021 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
@@ -39,7 +39,7 @@ import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.commons.lang3.StringUtils;
import org.apache.stratos.cli.exception.CommandException;
-import org.apache.stratos.cli.utils.CommandLineUtils;
+import org.apache.stratos.cli.utils.CliUtils;
import org.apache.stratos.cli.utils.RowMapper;
import org.apache.stratos.manager.dto.Cartridge;
import org.apache.stratos.manager.dto.PolicyDefinition;
@@ -209,7 +209,7 @@ public class CommandLineService {
}
System.out.println("Subscribed Cartridges:");
- CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
+ CliUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
System.out.println();
@@ -243,7 +243,7 @@ public class CommandLineService {
};
System.out.println("Available Multi-Tenant Cartridges:");
- CommandLineUtils.printTable(multiTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
+ CliUtils.printTable(multiTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
System.out.println();
Cartridge[] singleTenantCatridges = stub.getAvailableCartridges(false);
@@ -256,7 +256,7 @@ public class CommandLineService {
}
System.out.println("Available Single-Tenant Cartridges:");
- CommandLineUtils.printTable(singleTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
+ CliUtils.printTable(singleTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
System.out.println();
} catch (ApplicationManagementServiceADCExceptionException e) {
handleException("cannot.list.available.cartridges", e);
@@ -287,7 +287,7 @@ public class CommandLineService {
}
};
- CommandLineUtils.printTable(policies, policyMapper, "Policy Name", "Description", "Default");
+ CliUtils.printTable(policies, policyMapper, "Policy Name", "Description", "Default");
System.out.println();
} catch (RemoteException e) {
handleException(e);
@@ -542,7 +542,7 @@ public class CommandLineService {
if (logger.isDebugEnabled()) {
logger.debug("Displaying message for {}. Exception thrown is {}", key, e.getClass());
}
- String message = CommandLineUtils.getMessage(key, args);
+ String message = CliUtils.getMessage(key, args);
if (logger.isErrorEnabled()) {
logger.error(message);
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
index 48488e5..af2cb6f 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
@@ -31,7 +31,7 @@ import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.stratos.cli.exception.ExceptionMapper;
-import org.apache.stratos.cli.utils.CommandLineUtils;
+import org.apache.stratos.cli.utils.CliUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -222,7 +222,7 @@ public class RestClient implements GenericRestClient {
}
private void printError(HttpResponse response) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (StringUtils.isNotBlank(resultString)) {
// Response body found, try to extract exception information
boolean exceptionMapperInstanceFound = false;
@@ -275,7 +275,7 @@ public class RestClient implements GenericRestClient {
printError(response);
return null;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
return gson.fromJson(resultString, responseJsonClass);
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
index af8c214..7fd7d53 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
@@ -18,11 +18,7 @@
*/
package org.apache.stratos.cli;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
import java.net.ConnectException;
-import java.net.SocketException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -42,7 +38,6 @@ import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.transport.http.HttpTransportProperties;
-import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.impl.client.DefaultHttpClient;
@@ -65,7 +60,7 @@ import org.apache.stratos.cli.beans.topology.Member;
import org.apache.stratos.cli.exception.CommandException;
import org.apache.stratos.cli.exception.ExceptionMapper;
import org.apache.stratos.cli.utils.CliConstants;
-import org.apache.stratos.cli.utils.CommandLineUtils;
+import org.apache.stratos.cli.utils.CliUtils;
import org.apache.stratos.cli.utils.RowMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -243,7 +238,7 @@ public class RestCommandLineService {
response = restClient.doGet(httpClient, endpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
return null;
}
@@ -277,7 +272,7 @@ public class RestCommandLineService {
response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
return null;
@@ -319,7 +314,7 @@ public class RestCommandLineService {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
return;
}
@@ -393,7 +388,7 @@ public class RestCommandLineService {
cartridges = multiTelentCartridgeList.getCartridge().toArray(cartridges);
System.out.println("Available Multi-Tenant Cartridges:");
- CommandLineUtils.printTable(cartridges, cartridgeMapper, "Type", "Name", "Description", "Version", "Multitenanted");
+ CliUtils.printTable(cartridges, cartridgeMapper, "Type", "Name", "Description", "Version", "Multitenanted");
System.out.println();
}
@@ -410,7 +405,7 @@ public class RestCommandLineService {
cartridges1 = singleTeneCartridgetList.getCartridge().toArray(cartridges1 );
System.out.println("Available Single-Tenant Cartridges:");
- CommandLineUtils.printTable(cartridges1, cartridgeMapper, "Type", "Name", "Description", "Version", "Multitenanted", "Accessibility");
+ CliUtils.printTable(cartridges1, cartridgeMapper, "Type", "Name", "Description", "Version", "Multitenanted", "Accessibility");
System.out.println();
}
} catch (Exception e) {
@@ -427,7 +422,7 @@ public class RestCommandLineService {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
return;
}
@@ -470,7 +465,7 @@ public class RestCommandLineService {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listSubscribedCartridgesRestEndpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -547,7 +542,7 @@ public class RestCommandLineService {
}
System.out.println("Subscribed Cartridges:");
- CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
+ CliUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
System.out.println();
} catch (Exception e) {
@@ -565,7 +560,7 @@ public class RestCommandLineService {
+ listSubscribedCartridgeInfoRestEndpoint + alias);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -649,7 +644,7 @@ public class RestCommandLineService {
+ listClusterRestEndpoint + "lb");
String responseCode = "" + responseCluster.getStatusLine().getStatusCode();
- String resultStringCluster = CommandLineUtils.getHttpResponseString(responseCluster);
+ String resultStringCluster = CliUtils.getHttpResponseString(responseCluster);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -730,7 +725,7 @@ public class RestCommandLineService {
+"clusterId/"+ m.getLbClusterId());
String responseCode = "" + responseCluster.getStatusLine().getStatusCode();
- String resultStringCluster = CommandLineUtils.getHttpResponseString(responseCluster);
+ String resultStringCluster = CliUtils.getHttpResponseString(responseCluster);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -760,13 +755,13 @@ public class RestCommandLineService {
Gson gson = new Gson();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return null;
}
- Cluster cluster = getClusterObjectFromString(CommandLineUtils.getHttpResponseString(response));
+ Cluster cluster = getClusterObjectFromString(CliUtils.getHttpResponseString(response));
if (cluster == null) {
System.out.println("No existing subscriptions found for alias " + alias);
@@ -850,13 +845,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return null;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return null;
@@ -891,13 +886,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return null;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return null;
@@ -961,13 +956,13 @@ public class RestCommandLineService {
String responseCode = "" + response.getStatusLine().getStatusCode();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String subscriptionOutput = CommandLineUtils.getHttpResponseString(response);
+ String subscriptionOutput = CliUtils.getHttpResponseString(response);
if (subscriptionOutput == null) {
System.out.println("Error in response");
@@ -1032,7 +1027,7 @@ public class RestCommandLineService {
System.out.println("Tenant added successfully");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1072,7 +1067,7 @@ public class RestCommandLineService {
System.out.println("User added successfully");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1100,7 +1095,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully delete " + tenantDomain + " tenant");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1128,7 +1123,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully deleted " + userName + " user");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1156,7 +1151,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully deactivate " + tenantDomain + " tenant");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1184,7 +1179,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully activate " + tenantDomain + " tenant");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1204,7 +1199,7 @@ public class RestCommandLineService {
+ listAllTenantRestEndPoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -1254,7 +1249,7 @@ public class RestCommandLineService {
}
System.out.println("Available Tenants:" );
- CommandLineUtils.printTable(tenants, tenantInfoMapper, "Domain", "Tenant ID", "Email", "State", "Created Date");
+ CliUtils.printTable(tenants, tenantInfoMapper, "Domain", "Tenant ID", "Email", "State", "Created Date");
System.out.println();
} catch (Exception e) {
@@ -1272,7 +1267,7 @@ public class RestCommandLineService {
+ listAllUserRestEndPoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -1319,7 +1314,7 @@ public class RestCommandLineService {
}
System.out.println("Available Tenants:" );
- CommandLineUtils.printTable(users, userInfoMapper, "Username", "Role");
+ CliUtils.printTable(users, userInfoMapper, "Username", "Role");
System.out.println();
} catch (Exception e) {
@@ -1344,7 +1339,7 @@ public class RestCommandLineService {
System.out.println("You have successfully unsubscribed " + alias + " cartridge");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1372,7 +1367,7 @@ public class RestCommandLineService {
System.out.println("You have successfully deployed the cartridge");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1400,7 +1395,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully undeploy " + id + " cartridge");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1420,7 +1415,7 @@ public class RestCommandLineService {
+ partitionDeploymentEndPoint, partitionDefinition);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -1457,7 +1452,7 @@ public class RestCommandLineService {
System.out.println("You have successfully deployed the autoscaling policy");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1485,7 +1480,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully deploy the multi-tenant service cluster");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1513,7 +1508,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully undeploy multi-tenant service cluster");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1538,13 +1533,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return;
@@ -1582,7 +1577,7 @@ public class RestCommandLineService {
}
System.out.println("Available Deploy Services :");
- CommandLineUtils.printTable(definitionArry, deployServiceMapper, "Cartridge Type", "Deployment Policy Name",
+ CliUtils.printTable(definitionArry, deployServiceMapper, "Cartridge Type", "Deployment Policy Name",
"Autoscaling Policy Name", "Cluster Domain", "Tenant Range", "Accessibility");
System.out.println();
@@ -1609,7 +1604,7 @@ public class RestCommandLineService {
System.out.println("You have successfully deployed the deployment policy");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1629,7 +1624,7 @@ public class RestCommandLineService {
+ listParitionRestEndPoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -1677,7 +1672,7 @@ public class RestCommandLineService {
}
System.out.println("Available Partitions:" );
- CommandLineUtils.printTable(partitions, partitionMapper, "ID", "Provider", "Accessibilty");
+ CliUtils.printTable(partitions, partitionMapper, "ID", "Provider", "Accessibilty");
System.out.println();
} catch (Exception e) {
@@ -1700,13 +1695,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
@@ -1744,7 +1739,7 @@ public class RestCommandLineService {
}
System.out.println("Available Auto-scaling Policies:");
- CommandLineUtils.printTable(policyArry, partitionMapper, "ID", "Accessibility");
+ CliUtils.printTable(policyArry, partitionMapper, "ID", "Accessibility");
} catch (Exception e) {
handleException("Exception in listing autoscale policies", e);
@@ -1766,13 +1761,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return;
@@ -1809,7 +1804,7 @@ public class RestCommandLineService {
}
System.out.println("Available Deployment Policies:");
- CommandLineUtils.printTable(policyArry, partitionMapper, "ID", "Accessibility");
+ CliUtils.printTable(policyArry, partitionMapper, "ID", "Accessibility");
System.out.println();
} catch (Exception e) {
@@ -1832,13 +1827,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return;
@@ -1880,13 +1875,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return;
@@ -1923,13 +1918,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return;
@@ -1978,7 +1973,7 @@ public class RestCommandLineService {
KubernetesGroup[] array = new KubernetesGroup[list.getKubernetesGroup().size()];
array = list.getKubernetesGroup().toArray(array);
System.out.println("Available kubernetes groups:" );
- CommandLineUtils.printTable(array, partitionMapper, "Group ID", "Description");
+ CliUtils.printTable(array, partitionMapper, "Group ID", "Description");
} else {
System.out.println("No kubernetes groups found");
return;
@@ -2016,7 +2011,7 @@ public class RestCommandLineService {
KubernetesHost[] array = new KubernetesHost[list.getKubernetesHost().size()];
array = list.getKubernetesHost().toArray(array);
System.out.println("Available kubernetes hosts:" );
- CommandLineUtils.printTable(array, partitionMapper, "Host ID", "Hostname", "IP Address");
+ CliUtils.printTable(array, partitionMapper, "Host ID", "Hostname", "IP Address");
} else {
System.out.println("No kubernetes hosts found");
return;
@@ -2053,7 +2048,7 @@ public class RestCommandLineService {
} else {
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -2215,7 +2210,7 @@ public class RestCommandLineService {
logger.debug("Displaying message for {}. Exception thrown is {}", key, e.getClass());
}
- String message = CommandLineUtils.getMessage(key, args);
+ String message = CliUtils.getMessage(key, args);
if (logger.isErrorEnabled()) {
logger.error(message);
@@ -2247,7 +2242,7 @@ public class RestCommandLineService {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
return false;
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
index b76edcb..5df597d 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
@@ -96,7 +96,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new ExitCommand();
commands.put(command.getName(), command);
- command = new SubscribeCommand();
+ command = new SubscribeCartridgeCommand();
commands.put(command.getName(), command);
command = new UnsubscribeCommand();
@@ -126,16 +126,16 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new ActivateTenantCommand();
commands.put(command.getName(), command);
- command = new CartridgeDeploymentCommand();
+ command = new DeployCartridgeCommand();
commands.put(command.getName(), command);
- command = new PartitionDeploymentCommand();
+ command = new DeployPartitionCommand();
commands.put(command.getName(), command);
- command = new AutoscalingPolicyDeploymentCommand();
+ command = new DeployAutoscalingPolicyCommand();
commands.put(command.getName(), command);
- command = new DeployServiceDeploymentCommand();
+ command = new DeployServiceCommand();
commands.put(command.getName(), command);
command = new UndeployServiceDefinitionCommand();
@@ -147,19 +147,19 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new UndeployCartridgeDefinitionCommand();
commands.put(command.getName(), command);
- command = new DeploymentPolicyDeploymentCommand();
+ command = new DeployDeploymentPolicyCommand();
commands.put(command.getName(), command);
command = new ListSubscribedCartridgesCommand();
commands.put(command.getName(), command);
- command = new PartitionCommand();
+ command = new ListPartitionCommand();
commands.put(command.getName(), command);
- command = new AutoscalePolicyCommand();
+ command = new ListAutoscalePolicyCommand();
commands.put(command.getName(), command);
- command = new DeploymentPolicyCommand();
+ command = new ListDeploymentPolicyCommand();
commands.put(command.getName(), command);
command = new ListMemberCommand();
@@ -177,7 +177,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new DescribeAutoScalingPolicyCommand();
commands.put(command.getName(), command);
- command = new SubscribedCartridgeInfoCommand();
+ command = new ListCartridgeSubscriptionsCommand();
commands.put(command.getName(), command);
command = new SyncCommand();
@@ -292,14 +292,14 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
}
if (commandLine.hasOption(CliConstants.HELP_ACTION)) {
printHelp();
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
}
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments when trying to login", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
@@ -312,7 +312,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
Command<StratosCommandContext> command = commands.get(action);
if (command == null) {
printHelp();
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
boolean loginRequired = !CliConstants.HELP_ACTION.equals(action);
@@ -355,7 +355,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
promptLoop();
}
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
}
private boolean login(String usernameInput, String passwordInput, boolean validateLogin) {
@@ -427,7 +427,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
Command<StratosCommandContext> command = commands.get(action);
if (command == null) {
System.out.println(action + ": command not found.");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
try {
return command.execute(context, actionArgs);
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java
index 84acbc1..35fa624 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java
@@ -61,10 +61,10 @@ public class ActivateTenantCommand implements Command<StratosCommandContext> {
logger.debug("Getting deactivate tenant info {}", id);
}
RestCommandLineService.getInstance().activateTenant(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddDomainMappingCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddDomainMappingCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddDomainMappingCommand.java
index daafc61..773e64f 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddDomainMappingCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddDomainMappingCommand.java
@@ -68,14 +68,14 @@ public class AddDomainMappingCommand implements Command<StratosCommandContext> {
if (StringUtils.isBlank(domainToDisplay)) {
System.out.println("Error adding domain mapping.");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
} else {
System.out.format("Your own domain is added. Please CNAME it to systems domain %s.%n", domainToDisplay);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
}
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java
index b185f7d..3b9b218 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java
@@ -150,23 +150,23 @@ public class AddTenantCommand implements Command<StratosCommandContext> {
if (admin == null || firstName == null || lastaName == null || password == null || domain == null || email == null) {
System.out.println("usage: " + getName() + " [-u <user name>] [-f <first name>] [-l <last name>] [-p <password>] [-d <domain name>] [-e <email>]");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
RestCommandLineService.getInstance().addTenant(admin, firstName, lastaName, password, domain, email);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddUserCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddUserCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddUserCommand.java
index 331eca4..2eff5cc 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddUserCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddUserCommand.java
@@ -165,23 +165,23 @@ public class AddUserCommand implements Command<StratosCommandContext> {
if (userName == null || credential == null || role == null || firstName == null || lastName == null || email == null) {
System.out.println("usage: " + getName() + " [-u <user name>] [-p <credential>] [-r <role>] [-f <first name>] [-l <last name>] [-e <email>] [-pr <profile name>]");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
RestCommandLineService.getInstance().addUser(userName, credential, role, firstName, lastName, email, profileName);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalePolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalePolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalePolicyCommand.java
deleted file mode 100644
index 9c3b4ba..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalePolicyCommand.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * 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.stratos.cli.commands;
-
-import org.apache.commons.cli.Options;
-import org.apache.stratos.cli.Command;
-import org.apache.stratos.cli.RestCommandLineService;
-import org.apache.stratos.cli.StratosCommandContext;
-import org.apache.stratos.cli.exception.CommandException;
-import org.apache.stratos.cli.utils.CliConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class AutoscalePolicyCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(AutoscalePolicyCommand.class);
-
- public AutoscalePolicyCommand() {
- }
-
- public String getName() {
- return CliConstants.LIST_AUTOSCALE_POLICY;
- }
-
- public String getDescription() {
- return "List available autoscaling policies";
- }
-
- public String getArgumentSyntax() {
- return null;
- }
-
- public int execute(StratosCommandContext context, String[] args) throws CommandException {
- if (logger.isDebugEnabled()) {
- logger.debug("Executing {} command...", getName());
- }
- if (args == null || args.length == 0) {
- //CommandLineService.getInstance().listAvailableCartridges();
- RestCommandLineService.getInstance().listAutoscalePolicies();
- return CliConstants.SUCCESSFUL_CODE;
- } else {
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
- }
-
- public Options getOptions() {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalingPolicyDeploymentCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalingPolicyDeploymentCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalingPolicyDeploymentCommand.java
deleted file mode 100644
index ae44391..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalingPolicyDeploymentCommand.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * 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.stratos.cli.commands;
-
-import org.apache.commons.cli.*;
-import org.apache.stratos.cli.Command;
-import org.apache.stratos.cli.RestCommandLineService;
-import org.apache.stratos.cli.StratosCommandContext;
-import org.apache.stratos.cli.exception.CommandException;
-import org.apache.stratos.cli.utils.CliConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-
-public class AutoscalingPolicyDeploymentCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(AutoscalingPolicyDeploymentCommand.class);
-
- private final Options options;
-
- public AutoscalingPolicyDeploymentCommand(){
- options = constructOptions();
- }
-
- private Options constructOptions() {
- final Options options = new Options();
-
- Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
- "Autoscaling policy deployment resource path");
- resourcePath.setArgName("resource path");
- options.addOption(resourcePath);
-
- return options;
- }
-
- public String getName() {
- return CliConstants.AUTOSCALING_POLICY_DEPLOYMENT;
- }
-
- public String getDescription() {
- return "Add new autoscaling policy deployment";
- }
-
- public String getArgumentSyntax() {
- return null;
- }
-
- public int execute(StratosCommandContext context, String[] args) throws CommandException {
- if (logger.isDebugEnabled()) {
- logger.debug("Executing {} command...", getName());
- }
-
- if (args != null && args.length > 0) {
- String resourcePath = null;
- String autoscalingPolicyDeployment = null;
-
- final CommandLineParser parser = new GnuParser();
- CommandLine commandLine;
-
- try {
- commandLine = parser.parse(options, args);
-
- if (logger.isDebugEnabled()) {
- logger.debug("Autoscaling policy deployment");
- }
-
- if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Resource path option is passed");
- }
- resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
- autoscalingPolicyDeployment = readResource(resourcePath);
- }
-
- if (resourcePath == null) {
- System.out.println("usage: " + getName() + " [-p <resource path>]");
- return CliConstants.BAD_ARGS_CODE;
- }
-
- RestCommandLineService.getInstance().deployAutoscalingPolicy(autoscalingPolicyDeployment);
- return CliConstants.SUCCESSFUL_CODE;
-
- } catch (ParseException e) {
- if (logger.isErrorEnabled()) {
- logger.error("Error parsing arguments", e);
- }
- System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
- } catch (IOException e) {
- //e.printStackTrace();
- System.out.println("Invalid resource path");
- return CliConstants.BAD_ARGS_CODE;
- }
- } else {
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
- }
-
- private String readResource(String fileName) throws IOException {
- BufferedReader br = new BufferedReader(new FileReader(fileName));
- try {
- StringBuilder sb = new StringBuilder();
- String line = br.readLine();
-
- while (line != null) {
- sb.append(line);
- sb.append("\n");
- line = br.readLine();
- }
- return sb.toString();
- } finally {
- br.close();
- }
- }
-
- public Options getOptions() {
- return options;
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgeDeploymentCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgeDeploymentCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgeDeploymentCommand.java
deleted file mode 100644
index e60461c..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgeDeploymentCommand.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * 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.stratos.cli.commands;
-
-import org.apache.commons.cli.*;
-import org.apache.stratos.cli.Command;
-import org.apache.stratos.cli.RestCommandLineService;
-import org.apache.stratos.cli.StratosCommandContext;
-import org.apache.stratos.cli.exception.CommandException;
-import org.apache.stratos.cli.utils.CliConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-
-public class CartridgeDeploymentCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(CartridgeDeploymentCommand.class);
-
- private final Options options;
-
- public CartridgeDeploymentCommand(){
- options = constructOptions();
- }
-
- private Options constructOptions() {
- final Options options = new Options();
-
- Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
- "Cartridge deployment resource path");
- resourcePath.setArgName("resource path");
- options.addOption(resourcePath);
-
- return options;
- }
-
- public String getName() {
- return CliConstants.CARTRIDGE_DEPLOYMENT;
- }
-
- public String getDescription() {
- return "Add new cartridge deployment";
- }
-
- public String getArgumentSyntax() {
- return null;
- }
-
- public int execute(StratosCommandContext context, String[] args) throws CommandException {
- if (logger.isDebugEnabled()) {
- logger.debug("Executing {} command...", getName());
- }
-
- if (args != null && args.length > 0) {
- String resourcePath = null;
- String cartridgeDeploymentJSON = null;
-
- final CommandLineParser parser = new GnuParser();
- CommandLine commandLine;
-
- try {
- commandLine = parser.parse(options, args);
-
- if (logger.isDebugEnabled()) {
- logger.debug("Cartridge deployment");
- }
-
- if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Resource path option is passed");
- }
- resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
- cartridgeDeploymentJSON = readResource(resourcePath);
- }
-
- if (resourcePath == null) {
- System.out.println("usage: " + getName() + " [-p <resource path>]");
- return CliConstants.BAD_ARGS_CODE;
- }
-
- RestCommandLineService.getInstance().deployCartridgeDefinition(cartridgeDeploymentJSON);
- return CliConstants.SUCCESSFUL_CODE;
-
- } catch (ParseException e) {
- if (logger.isErrorEnabled()) {
- logger.error("Error parsing arguments", e);
- }
- System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
- } catch (IOException e) {
- //e.printStackTrace();
- System.out.println("Invalid resource path");
- return CliConstants.BAD_ARGS_CODE;
- }
-
-
- } else {
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
- }
-
- private String readResource(String fileName) throws IOException {
- BufferedReader br = new BufferedReader(new FileReader(fileName));
- try {
- StringBuilder sb = new StringBuilder();
- String line = br.readLine();
-
- while (line != null) {
- sb.append(line);
- sb.append("\n");
- line = br.readLine();
- }
- return sb.toString();
- } finally {
- br.close();
- }
- }
-
- public Options getOptions() {
- return options;
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java
index 83adf1f..ee9e15a 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java
@@ -61,10 +61,10 @@ public class DeactivateTenantCommand implements Command<StratosCommandContext> {
logger.debug("Getting deactivate tenant info {}", id);
}
RestCommandLineService.getInstance().deactivateTenant(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteTenantCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteTenantCommand.java
index 50b4a85..3c0b3f5 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteTenantCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteTenantCommand.java
@@ -61,10 +61,10 @@ public class DeleteTenantCommand implements Command<StratosCommandContext> {
logger.debug("Getting delete tenant info {}", id);
}
RestCommandLineService.getInstance().deleteTenant(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteUserCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteUserCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteUserCommand.java
index 9be1f26..2bf3e2d 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteUserCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteUserCommand.java
@@ -61,10 +61,10 @@ public class DeleteUserCommand implements Command<StratosCommandContext> {
logger.debug("Getting delete user info {}", username);
}
RestCommandLineService.getInstance().deleteUser(username);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployAutoscalingPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployAutoscalingPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployAutoscalingPolicyCommand.java
new file mode 100644
index 0000000..f6aa2ba
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployAutoscalingPolicyCommand.java
@@ -0,0 +1,138 @@
+/**
+ * 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.stratos.cli.commands;
+
+import org.apache.commons.cli.*;
+import org.apache.stratos.cli.Command;
+import org.apache.stratos.cli.RestCommandLineService;
+import org.apache.stratos.cli.StratosCommandContext;
+import org.apache.stratos.cli.exception.CommandException;
+import org.apache.stratos.cli.utils.CliConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+public class DeployAutoscalingPolicyCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeployAutoscalingPolicyCommand.class);
+
+ private final Options options;
+
+ public DeployAutoscalingPolicyCommand(){
+ options = constructOptions();
+ }
+
+ private Options constructOptions() {
+ final Options options = new Options();
+
+ Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+ "Autoscaling policy deployment resource path");
+ resourcePath.setArgName("resource path");
+ options.addOption(resourcePath);
+
+ return options;
+ }
+
+ public String getName() {
+ return CliConstants.AUTOSCALING_POLICY_DEPLOYMENT;
+ }
+
+ public String getDescription() {
+ return "Add new autoscaling policy deployment";
+ }
+
+ public String getArgumentSyntax() {
+ return null;
+ }
+
+ public int execute(StratosCommandContext context, String[] args) throws CommandException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing {} command...", getName());
+ }
+
+ if (args != null && args.length > 0) {
+ String resourcePath = null;
+ String autoscalingPolicyDeployment = null;
+
+ final CommandLineParser parser = new GnuParser();
+ CommandLine commandLine;
+
+ try {
+ commandLine = parser.parse(options, args);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Autoscaling policy deployment");
+ }
+
+ if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Resource path option is passed");
+ }
+ resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+ autoscalingPolicyDeployment = readResource(resourcePath);
+ }
+
+ if (resourcePath == null) {
+ System.out.println("usage: " + getName() + " [-p <resource path>]");
+ return CliConstants.COMMAND_FAILED;
+ }
+
+ RestCommandLineService.getInstance().deployAutoscalingPolicy(autoscalingPolicyDeployment);
+ return CliConstants.COMMAND_SUCCESSFULL;
+
+ } catch (ParseException e) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error parsing arguments", e);
+ }
+ System.out.println(e.getMessage());
+ return CliConstants.COMMAND_FAILED;
+ } catch (IOException e) {
+ //e.printStackTrace();
+ System.out.println("Invalid resource path");
+ return CliConstants.COMMAND_FAILED;
+ }
+ } else {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+ }
+
+ private String readResource(String fileName) throws IOException {
+ BufferedReader br = new BufferedReader(new FileReader(fileName));
+ try {
+ StringBuilder sb = new StringBuilder();
+ String line = br.readLine();
+
+ while (line != null) {
+ sb.append(line);
+ sb.append("\n");
+ line = br.readLine();
+ }
+ return sb.toString();
+ } finally {
+ br.close();
+ }
+ }
+
+ public Options getOptions() {
+ return options;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployCartridgeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployCartridgeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployCartridgeCommand.java
new file mode 100644
index 0000000..6982fc1
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployCartridgeCommand.java
@@ -0,0 +1,140 @@
+/**
+ * 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.stratos.cli.commands;
+
+import org.apache.commons.cli.*;
+import org.apache.stratos.cli.Command;
+import org.apache.stratos.cli.RestCommandLineService;
+import org.apache.stratos.cli.StratosCommandContext;
+import org.apache.stratos.cli.exception.CommandException;
+import org.apache.stratos.cli.utils.CliConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+public class DeployCartridgeCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeployCartridgeCommand.class);
+
+ private final Options options;
+
+ public DeployCartridgeCommand(){
+ options = constructOptions();
+ }
+
+ private Options constructOptions() {
+ final Options options = new Options();
+
+ Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+ "Cartridge deployment resource path");
+ resourcePath.setArgName("resource path");
+ options.addOption(resourcePath);
+
+ return options;
+ }
+
+ public String getName() {
+ return CliConstants.CARTRIDGE_DEPLOYMENT;
+ }
+
+ public String getDescription() {
+ return "Add new cartridge deployment";
+ }
+
+ public String getArgumentSyntax() {
+ return null;
+ }
+
+ public int execute(StratosCommandContext context, String[] args) throws CommandException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing {} command...", getName());
+ }
+
+ if (args != null && args.length > 0) {
+ String resourcePath = null;
+ String cartridgeDeploymentJSON = null;
+
+ final CommandLineParser parser = new GnuParser();
+ CommandLine commandLine;
+
+ try {
+ commandLine = parser.parse(options, args);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Cartridge deployment");
+ }
+
+ if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Resource path option is passed");
+ }
+ resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+ cartridgeDeploymentJSON = readResource(resourcePath);
+ }
+
+ if (resourcePath == null) {
+ System.out.println("usage: " + getName() + " [-p <resource path>]");
+ return CliConstants.COMMAND_FAILED;
+ }
+
+ RestCommandLineService.getInstance().deployCartridgeDefinition(cartridgeDeploymentJSON);
+ return CliConstants.COMMAND_SUCCESSFULL;
+
+ } catch (ParseException e) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error parsing arguments", e);
+ }
+ System.out.println(e.getMessage());
+ return CliConstants.COMMAND_FAILED;
+ } catch (IOException e) {
+ //e.printStackTrace();
+ System.out.println("Invalid resource path");
+ return CliConstants.COMMAND_FAILED;
+ }
+
+
+ } else {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+ }
+
+ private String readResource(String fileName) throws IOException {
+ BufferedReader br = new BufferedReader(new FileReader(fileName));
+ try {
+ StringBuilder sb = new StringBuilder();
+ String line = br.readLine();
+
+ while (line != null) {
+ sb.append(line);
+ sb.append("\n");
+ line = br.readLine();
+ }
+ return sb.toString();
+ } finally {
+ br.close();
+ }
+ }
+
+ public Options getOptions() {
+ return options;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployDeploymentPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployDeploymentPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployDeploymentPolicyCommand.java
new file mode 100644
index 0000000..f444894
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployDeploymentPolicyCommand.java
@@ -0,0 +1,138 @@
+/**
+ * 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.stratos.cli.commands;
+
+import org.apache.commons.cli.*;
+import org.apache.stratos.cli.Command;
+import org.apache.stratos.cli.RestCommandLineService;
+import org.apache.stratos.cli.StratosCommandContext;
+import org.apache.stratos.cli.exception.CommandException;
+import org.apache.stratos.cli.utils.CliConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+public class DeployDeploymentPolicyCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeployDeploymentPolicyCommand.class);
+
+ private final Options options;
+
+ public DeployDeploymentPolicyCommand(){
+ options = constructOptions();
+ }
+
+ private Options constructOptions() {
+ final Options options = new Options();
+
+ Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+ "Deployment policy deployment resource path");
+ resourcePath.setArgName("resource path");
+ options.addOption(resourcePath);
+
+ return options;
+ }
+
+ public String getName() {
+ return CliConstants.DEPLOYMENT_POLICY_DEPLOYMENT;
+ }
+
+ public String getDescription() {
+ return "Add new deployment policy";
+ }
+
+ public String getArgumentSyntax() {
+ return null;
+ }
+
+ public int execute(StratosCommandContext context, String[] args) throws CommandException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing {} command...", getName());
+ }
+
+ if (args != null && args.length > 0) {
+ String resourcePath = null;
+ String deploymentPolicyDeployment = null;
+
+ final CommandLineParser parser = new GnuParser();
+ CommandLine commandLine;
+
+ try {
+ commandLine = parser.parse(options, args);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Deployment policy deployment");
+ }
+
+ if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Resource path option is passed");
+ }
+ resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+ deploymentPolicyDeployment = readResource(resourcePath);
+ }
+
+ if (resourcePath == null) {
+ System.out.println("usage: " + getName() + " [-p <resource path>]");
+ return CliConstants.COMMAND_FAILED;
+ }
+
+ RestCommandLineService.getInstance().deployDeploymentPolicy(deploymentPolicyDeployment);
+ return CliConstants.COMMAND_SUCCESSFULL;
+
+ } catch (ParseException e) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error parsing arguments", e);
+ }
+ System.out.println(e.getMessage());
+ return CliConstants.COMMAND_FAILED;
+ } catch (IOException e) {
+ //e.printStackTrace();
+ System.out.println("Invalid resource path");
+ return CliConstants.COMMAND_FAILED;
+ }
+ } else {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+ }
+
+ private String readResource(String fileName) throws IOException {
+ BufferedReader br = new BufferedReader(new FileReader(fileName));
+ try {
+ StringBuilder sb = new StringBuilder();
+ String line = br.readLine();
+
+ while (line != null) {
+ sb.append(line);
+ sb.append("\n");
+ line = br.readLine();
+ }
+ return sb.toString();
+ } finally {
+ br.close();
+ }
+ }
+
+ public Options getOptions() {
+ return options;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
index 7b0ad24..e6f03fe 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
@@ -25,7 +25,7 @@ import org.apache.stratos.cli.RestCommandLineService;
import org.apache.stratos.cli.StratosCommandContext;
import org.apache.stratos.cli.exception.CommandException;
import org.apache.stratos.cli.utils.CliConstants;
-import org.apache.stratos.cli.utils.CommandLineUtils;
+import org.apache.stratos.cli.utils.CliUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,7 +75,7 @@ public class DeployKubernetesGroupCommand implements Command<StratosCommandConte
if ((args == null) || (args.length <= 0)) {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
try {
@@ -85,24 +85,24 @@ public class DeployKubernetesGroupCommand implements Command<StratosCommandConte
String resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
if (resourcePath == null) {
System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
- String resourceFileContent = CommandLineUtils.readResource(resourcePath);
+ String resourceFileContent = CliUtils.readResource(resourcePath);
RestCommandLineService.getInstance().deployKubernetesGroup(resourceFileContent);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
} catch (IOException e) {
System.out.println("Invalid resource path");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}