Mounting volumes script at Agent

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

Branch: refs/heads/master
Commit: ff50a0e3d35346a10f9747385d64cbe89ad8939d
Parents: 57df7cc
Author: Udara Liyanage <[email protected]>
Authored: Mon Feb 17 06:24:52 2014 -0500
Committer: Udara Liyanage <[email protected]>
Committed: Mon Feb 17 06:24:52 2014 -0500

----------------------------------------------------------------------
 .../stratos/cartridge/agent/CartridgeAgent.java |  3 ++
 .../agent/util/CartridgeAgentConstants.java     |  1 +
 .../cartridge/agent/util/ExtensionUtils.java    | 21 ++++++++
 .../src/main/extensions/mount_volumes.sh        | 56 ++++++++++++++++++++
 4 files changed, 81 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ff50a0e3/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java
 
b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java
index 5ab6634..3e95da0 100644
--- 
a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java
+++ 
b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java
@@ -120,6 +120,9 @@ public class CartridgeAgent implements Runnable {
         // Wait for all ports to be active
         CartridgeAgentUtils.waitUntilPortsActive("localhost", 
CartridgeAgentConfiguration.getInstance().getPorts());
 
+        // Mount persistance volumes.
+        ExtensionUtils.executeVolumeMountExtension();
+
         // Check repo url
         String repoUrl = 
CartridgeAgentConfiguration.getInstance().getRepoUrl();
         if ("null".equals(repoUrl) || StringUtils.isBlank(repoUrl)) {

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ff50a0e3/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/CartridgeAgentConstants.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/CartridgeAgentConstants.java
 
b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/CartridgeAgentConstants.java
index f133201..80e3bc2 100644
--- 
a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/CartridgeAgentConstants.java
+++ 
b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/CartridgeAgentConstants.java
@@ -32,6 +32,7 @@ public class CartridgeAgentConstants implements Serializable{
     public static final String INSTANCE_ACTIVATED_SH = "instance-activated.sh";
     public static final String ARTIFACTS_UPDATED_SH = "artifacts-updated.sh";
     public static final String CLEAN_UP_SH = "clean.sh";
+    public static final String MOUNT_VOLUMES_SH = "mount_volumes.sh";
        
        public static final String CARTRIDGE_KEY = "CARTRIDGE_KEY";
        public static final String APP_PATH = "APP_PATH";

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ff50a0e3/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java
 
b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java
index e164022..d45ff2b 100644
--- 
a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java
+++ 
b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java
@@ -111,4 +111,25 @@ public class ExtensionUtils {
             log.error("Could not execute artifacts updated extension", e);
         }
     }
+
+    /*
+    This will execute the volume mounting script which format and mount the
+    persistance volumes.
+     */
+    public static void executeVolumeMountExtension() {
+        try {
+            if(log.isDebugEnabled()) {
+                    log.debug("Executing volume mounting extension");
+            }
+            String command = 
prepareCommand(CartridgeAgentConstants.MOUNT_VOLUMES_SH);
+            String payloadPath = 
System.getProperty(CartridgeAgentConstants.PARAM_FILE_PATH);
+
+            // add payload file path as argument so inside the script we can 
source
+            // it  to get the env variables set by the startup script
+            CommandUtils.executeCommand(command + " " + payloadPath);
+        }
+        catch (Exception e) {
+                log.error("Could not execute volume mounting extension", e);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ff50a0e3/products/cartridge-agent/modules/distribution/src/main/extensions/mount_volumes.sh
----------------------------------------------------------------------
diff --git 
a/products/cartridge-agent/modules/distribution/src/main/extensions/mount_volumes.sh
 
b/products/cartridge-agent/modules/distribution/src/main/extensions/mount_volumes.sh
new file mode 100755
index 0000000..9f91a6b
--- /dev/null
+++ 
b/products/cartridge-agent/modules/distribution/src/main/extensions/mount_volumes.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+# --------------------------------------------------------------
+#
+# 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.
+#
+# --------------------------------------------------------------
+# This extension script will be executed to start the servers.
+# --------------------------------------------------------------
+#
+
+log=/var/log/apache-stratos/cartridge-agent-extensions.log
+echo -e "Starting mounting volumes" | tee -a $log
+
+# $1 refers the payload params file which is passed from Cartridge Agent code.
+source $1
+
+function mount_volume(){
+       echo -e "Formating the device $1 \n"
+       sudo mkfs -t ext4 $1
+
+       echo "Mounting  the device $1 to the mount point $2 \n"
+       if [ -d "$DIRECTORY" ]; then
+               echo "creating the directory $2 since it does not exist."
+               mkdir $2        
+       fi
+
+       sudo mount $1 $2
+}
+
+IFS='|' read -ra ADDR <<< "$PERSISTANCE_MAPPING"
+for i in "${!ADDR[@]}"; do
+       # expected PERSISTANCE_MAPPING format is 
device1|mountPoint1|device2|mountpoint2...
+       # so that even indexes are devices and odd indexes are mount points..
+
+       if (( $i  % 2 == 0 ))
+       then
+          mount_volume ${ADDR[$i]} ${ADDR[$i + 1]}
+       fi
+done
+
+echo $IFS

Reply via email to