You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2015/02/18 11:15:29 UTC
[03/10] stratos git commit: CLI command added to remove Deployment
Policy.
CLI command added to remove Deployment Policy.
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/3b462f39
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/3b462f39
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/3b462f39
Branch: refs/heads/4.1.0-beta-deployment-policy-fix
Commit: 3b462f393e05edd0453fa61ff5a778b7a1517321
Parents: 828c49d
Author: Dinithi <di...@wso2.com>
Authored: Mon Feb 16 17:12:01 2015 +0530
Committer: Dinithi <di...@wso2.com>
Committed: Mon Feb 16 17:12:01 2015 +0530
----------------------------------------------------------------------
.../java/org/apache/stratos/cli/RestClient.java | 2 +-
.../stratos/cli/RestCommandLineService.java | 11 ++-
.../apache/stratos/cli/StratosApplication.java | 3 +
.../commands/RemoveDeploymentPolicyCommand.java | 71 ++++++++++++++++++++
4 files changed, 85 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/3b462f39/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 d1b9fb9..eeb0302 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
@@ -202,7 +202,7 @@ public class RestClient implements GenericRestClient {
int responseCode = executeDelete(serviceEndpoint, identifier);
if (responseCode == 404) {
System.out.println(String.format("%s not found", StringUtils.capitalize(entityName)));
- } else if (responseCode == 200) {
+ } else if (responseCode >= 200 && responseCode < 300) {
System.out.println(String.format("Successfully deleted %s", entityName));
}
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/stratos/blob/3b462f39/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 7923f39..3256e85 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
@@ -91,8 +91,8 @@ public class RestCommandLineService {
private static final String ENDPOINT_REMOVE_APPLICATION = API_CONTEXT + "/applications/{appId}";
private static final String ENDPOINT_REMOVE_NETWORK_PARTITION = API_CONTEXT + "/networkPartitions/{id}";
-
private static final String ENDPOINT_REMOVE_AUTOSCALINGPOLICY = API_CONTEXT + "/autoscalingPolicies/{policyId}";
+ private static final String ENDPOINT_REMOVE_DEPLOYMENT_POLICY = API_CONTEXT + "/deploymentPolicies/{policyId}";
private static final String ENDPOINT_LIST_AUTOSCALING_POLICIES = API_CONTEXT + "/autoscalingPolicies";
private static final String ENDPOINT_LIST_DEPLOYMENT_POLICIES = API_CONTEXT + "/deploymentPolicies";
@@ -1348,4 +1348,13 @@ public class RestCommandLineService {
public void updateDeploymentPolicy(String deploymentPolicy) throws CommandException {
restClient.updateEntity(ENDPOINT_UPDATE_DEPLOYMENT_POLICY, deploymentPolicy, "deployment policy");
}
+
+ /**
+ * Delete deployment policy
+ * @throws CommandException
+ */
+ public void deleteDeploymentPolicy(String policyId) {
+ restClient.deleteEntity(ENDPOINT_REMOVE_DEPLOYMENT_POLICY.replace("{policyId}", policyId), policyId,
+ "deployment policy");
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/3b462f39/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 41dd715..9589490 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
@@ -228,6 +228,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new UpdateDeploymentPolicyCommand();
commands.put(command.getName(), command);
+ command = new RemoveDeploymentPolicyCommand();
+ commands.put(command.getName(), command);
+
if (logger.isDebugEnabled()) {
logger.debug("Created {} commands for the application. {}", commands.size(), commands.keySet());
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/3b462f39/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveDeploymentPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveDeploymentPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveDeploymentPolicyCommand.java
new file mode 100644
index 0000000..31d7905
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveDeploymentPolicyCommand.java
@@ -0,0 +1,71 @@
+/**
+ * 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 RemoveDeploymentPolicyCommand implements Command<StratosCommandContext> {
+ private static final Logger logger = LoggerFactory.getLogger(RemoveDeploymentPolicyCommand.class);
+
+ @Override
+ public String getName() {
+ return "remove-deployment-policy";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Remove Deployment policy";
+ }
+
+ @Override
+ public String getArgumentSyntax() {
+ return "[Deployment-policy Id]";
+ }
+
+ @Override
+ public Options getOptions() {
+ return null;
+ }
+
+ @Override
+ public int execute(StratosCommandContext context, String[] args) throws CommandException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing {} command...", getName());
+ }
+ if (args != null && args.length == 1) {
+ String id = args[0];
+ if (logger.isDebugEnabled()) {
+ logger.debug("Getting Deployment-policy Id {}", id);
+ }
+ RestCommandLineService.getInstance().deleteDeploymentPolicy(id);
+ return CliConstants.COMMAND_SUCCESSFULL;
+ } else {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+ }
+}