You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/10/11 07:48:03 UTC

[1/2] git commit: Adding a option to CLI tool to subscribe with a json file.

Repository: stratos
Updated Branches:
  refs/heads/master 2d9895fdd -> f2252b7c5


Adding a option to CLI tool to subscribe with a json file.


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

Branch: refs/heads/master
Commit: f2252b7c5add73854c761afe1805965345ccd82b
Parents: 53a4d1f
Author: Nirmal Fernando <ni...@gmail.com>
Authored: Sat Oct 11 11:17:12 2014 +0530
Committer: Nirmal Fernando <ni...@gmail.com>
Committed: Sat Oct 11 11:17:34 2014 +0530

----------------------------------------------------------------------
 .../stratos/cli/RestCommandLineService.java     | 56 ++++++++++++++++++++
 .../stratos/cli/commands/SubscribeCommand.java  | 48 +++++++++++++++++
 2 files changed, 104 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/f2252b7c/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 fb5c2ff..e2b006b 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
@@ -1003,6 +1003,62 @@ public class RestCommandLineService {
             httpClient.getConnectionManager().shutdown();
         }
     }
+    
+ // This method does the cartridge subscription
+    public void subscribe(String subscriptionJson)
+            throws CommandException {
+        
+        DefaultHttpClient httpClient = new DefaultHttpClient();
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        Gson gson = gsonBuilder.create();
+        
+        try {
+            HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + subscribCartridgeRestEndpoint,
+                    subscriptionJson);
+
+            String responseCode = "" + response.getStatusLine().getStatusCode();
+
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                String resultString = CommandLineUtils.getHttpResponseString(response);
+                ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+                System.out.println(exception);
+                return;
+            }
+
+            String subscriptionOutput = CommandLineUtils.getHttpResponseString(response);
+
+            if (subscriptionOutput == null) {
+                System.out.println("Error in response");
+                return;
+            }
+
+            String  subscriptionOutputJSON = subscriptionOutput.substring(20, subscriptionOutput.length() -1);
+            SubscriptionInfo subcriptionInfo = gson.fromJson(subscriptionOutputJSON, SubscriptionInfo.class);
+
+            System.out.format("You have successfully subscribed.");
+
+            String repoURL;
+            String hostnames = null;
+            String hostnamesLabel = null;
+            if (subcriptionInfo != null) {
+                repoURL = subcriptionInfo.getRepositoryURL();
+                hostnames = subcriptionInfo.getHostname();
+                hostnamesLabel = "host name";
+
+                if (repoURL != null) {
+                    System.out.println("GIT Repository URL: " + repoURL);
+                }
+            }
+
+            System.out.format("Please map the %s \"%s\" to LB IP%n", hostnamesLabel, hostnames);
+
+        } catch (Exception e) {
+            handleException("Exception in subscribing to cartridge", e);
+        } finally {
+            httpClient.getConnectionManager().shutdown();
+        }
+        
+    }
 
     // This method helps to create the new tenant
     public void addTenant(String admin, String firstName, String lastaName, String password, String domain, String email)

http://git-wip-us.apache.org/repos/asf/stratos/blob/f2252b7c/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
index e8eca38..0e78b5b 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
@@ -34,6 +34,9 @@ import org.apache.stratos.cli.StratosCommandContext;
 import org.apache.stratos.cli.exception.CommandException;
 import org.apache.stratos.cli.utils.CliConstants;
 
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
 import java.util.ArrayList;
 
 public class SubscribeCommand implements Command<StratosCommandContext> {
@@ -58,6 +61,11 @@ public class SubscribeCommand implements Command<StratosCommandContext> {
         //				+ "\" command to view the available policies.");
         //policyOption.setArgName("policy name");
         //options.addOption(policyOption);
+        
+        Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+                "Cartridge deployment resource path");
+        resourcePath.setArgName("resource path");
+        options.addOption(resourcePath);
 
         Option autoscaling = new Option(CliConstants.AUTOSCALING_POLICY_OPTION, CliConstants.AUTOSCALING_POLICY_LONG_OPTION,
                 true, "Auto-scaling policy");
@@ -141,6 +149,8 @@ public class SubscribeCommand implements Command<StratosCommandContext> {
             String repoURL = null, username = "", password = "";
             String size = null;
             String volumeID = null;
+            String resourcePath = null;
+            String subscriptionJson = null;
 
             boolean removeOnTermination = false;
             boolean privateRepo = false;
@@ -157,6 +167,27 @@ public class SubscribeCommand implements Command<StratosCommandContext> {
                     // Get type
                     type = remainingArgs[0];
                     alias = remainingArgs[1];
+                } else if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Resource path option is passed");
+                    }
+                    try {
+                        resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+                        subscriptionJson = readResource(resourcePath);
+                    } catch (IOException e) {
+                        // e.printStackTrace();
+                        System.out.println("Invalid resource path");
+                        return CliConstants.BAD_ARGS_CODE;
+                    }
+                    
+                    if (resourcePath == null) {
+                        System.out.println("usage: " + getName() + " [-p <resource path>]");
+                        return CliConstants.BAD_ARGS_CODE;
+                    }
+
+                    RestCommandLineService.getInstance().subscribe(subscriptionJson);
+                    return CliConstants.SUCCESSFUL_CODE;
+                    
                 } else {
                     context.getStratosApplication().printUsage(getName());
                     return CliConstants.BAD_ARGS_CODE;
@@ -303,6 +334,23 @@ public class SubscribeCommand implements Command<StratosCommandContext> {
 			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;


[2/2] git commit: Pod activation should run only when IP of the pod is null.

Posted by ni...@apache.org.
Pod activation should run only when IP of the pod is null.


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

Branch: refs/heads/master
Commit: 53a4d1fd5e16522bbaa935fadb0768c8ccb98676
Parents: 2d9895f
Author: Nirmal Fernando <ni...@gmail.com>
Authored: Sat Oct 11 11:16:21 2014 +0530
Committer: Nirmal Fernando <ni...@gmail.com>
Committed: Sat Oct 11 11:17:34 2014 +0530

----------------------------------------------------------------------
 .../apache/stratos/cloud/controller/util/PodActivationWatcher.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/53a4d1fd/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java
index 23924b4..c142abf 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java
@@ -53,7 +53,7 @@ public class PodActivationWatcher implements Runnable {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("PodActivationWatcher running : "+pod.getCurrentState().getStatus());
             }
-            if ("Running".equals(pod.getCurrentState().getStatus()) && dataHolder.getMemberContextOfMemberId(podId) == null) {
+            if ("Running".equals(pod.getCurrentState().getStatus()) && ctxt.getPublicIpAddress() == null) {
                 String hostIP = pod.getCurrentState().getHost();
                 ctxt.setPublicIpAddress(hostIP);
                 ctxt.setPrivateIpAddress(hostIP);