You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ga...@apache.org on 2015/01/26 18:57:09 UTC

[1/3] stratos git commit: Avoid delete the Application without undeploying the Application

Repository: stratos
Updated Branches:
  refs/heads/master 9c191dd27 -> 2a9e2d478


Avoid delete the Application without undeploying the Application


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/3d5e2536
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/3d5e2536
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/3d5e2536

Branch: refs/heads/master
Commit: 3d5e253651484fa3ead53294d9704bb106d0d245
Parents: 9c191dd
Author: Gayan Gunarathne <ga...@wso2.com>
Authored: Mon Jan 26 22:16:56 2015 +0530
Committer: Gayan Gunarathne <ga...@wso2.com>
Committed: Mon Jan 26 22:16:56 2015 +0530

----------------------------------------------------------------------
 .../java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java  | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/3d5e2536/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
index aeef4c2..cf6a420 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
@@ -704,6 +704,9 @@ public class StratosApiV41 extends AbstractApi {
         if (applicationDefinition == null) {
             return Response.status(Response.Status.NOT_FOUND).build();
         }
+	    if (StratosApiV41Utils.getApplicationRuntime(applicationId) != null) {
+		    return Response.status(Response.Status.NOT_ACCEPTABLE).build();
+	    }
         StratosApiV41Utils.removeApplication(applicationId);
         return Response.noContent().build();
     }


[2/3] stratos git commit: Add a CLI command to update cartridge

Posted by ga...@apache.org.
Add a CLI command to update cartridge


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/2c132c16
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/2c132c16
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/2c132c16

Branch: refs/heads/master
Commit: 2c132c16a5ae4402cfb8121b12266d020e480f57
Parents: 3d5e253
Author: Gayan Gunarathne <ga...@wso2.com>
Authored: Mon Jan 26 23:05:50 2015 +0530
Committer: Gayan Gunarathne <ga...@wso2.com>
Committed: Mon Jan 26 23:05:50 2015 +0530

----------------------------------------------------------------------
 .../stratos/cli/RestCommandLineService.java     |   7 +-
 .../apache/stratos/cli/StratosApplication.java  |   3 +
 .../cli/commands/UpdateCartridgeCommand.java    | 140 +++++++++++++++++++
 .../impl/CloudControllerServiceImpl.java        |   4 +-
 4 files changed, 151 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/2c132c16/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 12ae7cd..ed7173b 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
@@ -624,11 +624,16 @@ public class RestCommandLineService {
         }
     }
 
-    // This method helps to deploy cartridge definitions
+    // This method helps to add cartridge definitions
     public void addCartridge(String cartridgeDefinition) throws CommandException {
         restClient.deployEntity(ENDPOINT_DEPLOY_CARTRIDGE, cartridgeDefinition, "cartridge");
     }
 
+	// This method helps to update cartridge definitions
+	public void updateCartridge(String cartridgeDefinition) throws CommandException {
+		restClient.updateEntity(ENDPOINT_DEPLOY_CARTRIDGE, cartridgeDefinition, "cartridge");
+	}
+
     // This method helps to undeploy cartridge definitions
     public void undeployCartrigdeDefinition(String id) throws CommandException {
         restClient.undeployEntity(ENDPOINT_UNDEPLOY_CARTRIDGE, "cartridge", id);

http://git-wip-us.apache.org/repos/asf/stratos/blob/2c132c16/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 43892cb..b6703d2 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
@@ -117,6 +117,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
         command = new AddCartridgeCommand();
         commands.put(command.getName(), command);
 
+		command = new UpdateCartridgeCommand();
+		commands.put(command.getName(), command);
+
         command = new AddAutoscalingPolicyCommand();
         commands.put(command.getName(), command);
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/2c132c16/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateCartridgeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateCartridgeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateCartridgeCommand.java
new file mode 100644
index 0000000..da5cb1f
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateCartridgeCommand.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 UpdateCartridgeCommand implements Command<StratosCommandContext> {
+
+    private static final Logger logger = LoggerFactory.getLogger(UpdateCartridgeCommand.class);
+
+    private final Options options;
+
+    public UpdateCartridgeCommand(){
+        options = constructOptions();
+    }
+
+    private Options constructOptions() {
+        final Options options = new Options();
+
+        Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+                "Cartridge resource path");
+        resourcePath.setArgName("resource path");
+        options.addOption(resourcePath);
+
+        return options;
+    }
+
+    public String getName() {
+        return "update-cartridge";
+    }
+
+    public String getDescription() {
+        return "Update 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 cartridgeJson = 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);
+                    cartridgeJson = readResource(resourcePath);
+                }
+
+                if (resourcePath == null) {
+                    System.out.println("usage: " + getName() + " [-p <resource path>]");
+                    return CliConstants.COMMAND_FAILED;
+                }
+
+                RestCommandLineService.getInstance().updateCartridge(cartridgeJson);
+                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) {
+                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/2c132c16/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
index 0925580..bf3e1f8 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
@@ -1058,11 +1058,11 @@ public class CloudControllerServiceImpl implements CloudControllerService {
 					        for (PortMapping portMap : portMappings) {
 						        if (portMap.isKubernetesServicePortMapping()) {
 							        String accessUrl =
-									        portMap.getProtocol() + ":".concat("\\\\")+ appClusterCtxt.getHostName() + ":" + portMap.getKubernetesServicePort();
+									        portMap.getProtocol() + ":".concat("//")+ appClusterCtxt.getHostName() + ":" + portMap.getKubernetesServicePort();
 							        accessUrlPerCluster.add(accessUrl);
 						        } else {
 							        String accessUrl =
-									        portMap.getProtocol()+ ":".concat("\\\\") + appClusterCtxt.getHostName() + ":" +  portMap.getProxyPort();
+									        portMap.getProtocol()+ ":".concat("//") + appClusterCtxt.getHostName() + ":" +  portMap.getProxyPort();
 							        accessUrlPerCluster.add(accessUrl);
 						        }
 					        }


[3/3] stratos git commit: Add a CLI command to update cartridge

Posted by ga...@apache.org.
Add a CLI command to update cartridge


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/2a9e2d47
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/2a9e2d47
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/2a9e2d47

Branch: refs/heads/master
Commit: 2a9e2d47874e997ac32e6f9559014c285367c303
Parents: 2c132c1
Author: Gayan Gunarathne <ga...@wso2.com>
Authored: Mon Jan 26 23:26:09 2015 +0530
Committer: Gayan Gunarathne <ga...@wso2.com>
Committed: Mon Jan 26 23:26:09 2015 +0530

----------------------------------------------------------------------
 .../src/main/java/org/apache/stratos/cli/RestClient.java          | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/2a9e2d47/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 af1c8a4..d1b9fb9 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
@@ -30,7 +30,6 @@ import org.apache.http.entity.StringEntity;
 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.CliUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -188,7 +187,7 @@ public class RestClient implements GenericRestClient {
             int responseCode = executePut(serviceEndpoint, entityBody);
             if (responseCode == 404) {
                 System.out.println(String.format("%s not found", StringUtils.capitalize(entityName)));
-            } else if (responseCode == 200) {
+            } else if (responseCode == 201) {
                 System.out.println(String.format("Successfully updated %s", entityName));
             }
         } catch (Exception e) {