You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by nd...@apache.org on 2015/05/01 23:33:27 UTC

[40/57] [partial] airavata-php-gateway git commit: AIRAVATA 1632 + Job Description for Admin Dashboard

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/app/libraries/Airavata/Model/Workspace/Types.php
----------------------------------------------------------------------
diff --git a/app/libraries/Airavata/Model/Workspace/Types.php b/app/libraries/Airavata/Model/Workspace/Types.php
new file mode 100644
index 0000000..7ccd55c
--- /dev/null
+++ b/app/libraries/Airavata/Model/Workspace/Types.php
@@ -0,0 +1,608 @@
+<?php
+namespace Airavata\Model\Workspace;
+
+/**
+ * Autogenerated by Thrift Compiler (0.9.1)
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ *  @generated
+ */
+use Thrift\Base\TBase;
+use Thrift\Type\TType;
+use Thrift\Type\TMessageType;
+use Thrift\Exception\TException;
+use Thrift\Exception\TProtocolException;
+use Thrift\Protocol\TProtocol;
+use Thrift\Protocol\TBinaryProtocolAccelerated;
+use Thrift\Exception\TApplicationException;
+
+
+class Group {
+  static $_TSPEC;
+
+  public $groupName = null;
+  public $description = null;
+
+  public function __construct($vals=null) {
+    if (!isset(self::$_TSPEC)) {
+      self::$_TSPEC = array(
+        1 => array(
+          'var' => 'groupName',
+          'type' => TType::STRING,
+          ),
+        2 => array(
+          'var' => 'description',
+          'type' => TType::STRING,
+          ),
+        );
+    }
+    if (is_array($vals)) {
+      if (isset($vals['groupName'])) {
+        $this->groupName = $vals['groupName'];
+      }
+      if (isset($vals['description'])) {
+        $this->description = $vals['description'];
+      }
+    }
+  }
+
+  public function getName() {
+    return 'Group';
+  }
+
+  public function read($input)
+  {
+    $xfer = 0;
+    $fname = null;
+    $ftype = 0;
+    $fid = 0;
+    $xfer += $input->readStructBegin($fname);
+    while (true)
+    {
+      $xfer += $input->readFieldBegin($fname, $ftype, $fid);
+      if ($ftype == TType::STOP) {
+        break;
+      }
+      switch ($fid)
+      {
+        case 1:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->groupName);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 2:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->description);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        default:
+          $xfer += $input->skip($ftype);
+          break;
+      }
+      $xfer += $input->readFieldEnd();
+    }
+    $xfer += $input->readStructEnd();
+    return $xfer;
+  }
+
+  public function write($output) {
+    $xfer = 0;
+    $xfer += $output->writeStructBegin('Group');
+    if ($this->groupName !== null) {
+      $xfer += $output->writeFieldBegin('groupName', TType::STRING, 1);
+      $xfer += $output->writeString($this->groupName);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->description !== null) {
+      $xfer += $output->writeFieldBegin('description', TType::STRING, 2);
+      $xfer += $output->writeString($this->description);
+      $xfer += $output->writeFieldEnd();
+    }
+    $xfer += $output->writeFieldStop();
+    $xfer += $output->writeStructEnd();
+    return $xfer;
+  }
+
+}
+
+class Project {
+  static $_TSPEC;
+
+  public $projectID = "DEFAULT";
+  public $owner = null;
+  public $name = null;
+  public $description = null;
+  public $creationTime = null;
+  public $sharedUsers = null;
+  public $sharedGroups = null;
+
+  public function __construct($vals=null) {
+    if (!isset(self::$_TSPEC)) {
+      self::$_TSPEC = array(
+        1 => array(
+          'var' => 'projectID',
+          'type' => TType::STRING,
+          ),
+        2 => array(
+          'var' => 'owner',
+          'type' => TType::STRING,
+          ),
+        3 => array(
+          'var' => 'name',
+          'type' => TType::STRING,
+          ),
+        4 => array(
+          'var' => 'description',
+          'type' => TType::STRING,
+          ),
+        5 => array(
+          'var' => 'creationTime',
+          'type' => TType::I64,
+          ),
+        6 => array(
+          'var' => 'sharedUsers',
+          'type' => TType::LST,
+          'etype' => TType::STRING,
+          'elem' => array(
+            'type' => TType::STRING,
+            ),
+          ),
+        7 => array(
+          'var' => 'sharedGroups',
+          'type' => TType::LST,
+          'etype' => TType::STRING,
+          'elem' => array(
+            'type' => TType::STRING,
+            ),
+          ),
+        );
+    }
+    if (is_array($vals)) {
+      if (isset($vals['projectID'])) {
+        $this->projectID = $vals['projectID'];
+      }
+      if (isset($vals['owner'])) {
+        $this->owner = $vals['owner'];
+      }
+      if (isset($vals['name'])) {
+        $this->name = $vals['name'];
+      }
+      if (isset($vals['description'])) {
+        $this->description = $vals['description'];
+      }
+      if (isset($vals['creationTime'])) {
+        $this->creationTime = $vals['creationTime'];
+      }
+      if (isset($vals['sharedUsers'])) {
+        $this->sharedUsers = $vals['sharedUsers'];
+      }
+      if (isset($vals['sharedGroups'])) {
+        $this->sharedGroups = $vals['sharedGroups'];
+      }
+    }
+  }
+
+  public function getName() {
+    return 'Project';
+  }
+
+  public function read($input)
+  {
+    $xfer = 0;
+    $fname = null;
+    $ftype = 0;
+    $fid = 0;
+    $xfer += $input->readStructBegin($fname);
+    while (true)
+    {
+      $xfer += $input->readFieldBegin($fname, $ftype, $fid);
+      if ($ftype == TType::STOP) {
+        break;
+      }
+      switch ($fid)
+      {
+        case 1:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->projectID);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 2:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->owner);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 3:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->name);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 4:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->description);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 5:
+          if ($ftype == TType::I64) {
+            $xfer += $input->readI64($this->creationTime);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 6:
+          if ($ftype == TType::LST) {
+            $this->sharedUsers = array();
+            $_size0 = 0;
+            $_etype3 = 0;
+            $xfer += $input->readListBegin($_etype3, $_size0);
+            for ($_i4 = 0; $_i4 < $_size0; ++$_i4)
+            {
+              $elem5 = null;
+              $xfer += $input->readString($elem5);
+              $this->sharedUsers []= $elem5;
+            }
+            $xfer += $input->readListEnd();
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 7:
+          if ($ftype == TType::LST) {
+            $this->sharedGroups = array();
+            $_size6 = 0;
+            $_etype9 = 0;
+            $xfer += $input->readListBegin($_etype9, $_size6);
+            for ($_i10 = 0; $_i10 < $_size6; ++$_i10)
+            {
+              $elem11 = null;
+              $xfer += $input->readString($elem11);
+              $this->sharedGroups []= $elem11;
+            }
+            $xfer += $input->readListEnd();
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        default:
+          $xfer += $input->skip($ftype);
+          break;
+      }
+      $xfer += $input->readFieldEnd();
+    }
+    $xfer += $input->readStructEnd();
+    return $xfer;
+  }
+
+  public function write($output) {
+    $xfer = 0;
+    $xfer += $output->writeStructBegin('Project');
+    if ($this->projectID !== null) {
+      $xfer += $output->writeFieldBegin('projectID', TType::STRING, 1);
+      $xfer += $output->writeString($this->projectID);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->owner !== null) {
+      $xfer += $output->writeFieldBegin('owner', TType::STRING, 2);
+      $xfer += $output->writeString($this->owner);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->name !== null) {
+      $xfer += $output->writeFieldBegin('name', TType::STRING, 3);
+      $xfer += $output->writeString($this->name);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->description !== null) {
+      $xfer += $output->writeFieldBegin('description', TType::STRING, 4);
+      $xfer += $output->writeString($this->description);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->creationTime !== null) {
+      $xfer += $output->writeFieldBegin('creationTime', TType::I64, 5);
+      $xfer += $output->writeI64($this->creationTime);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->sharedUsers !== null) {
+      if (!is_array($this->sharedUsers)) {
+        throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
+      }
+      $xfer += $output->writeFieldBegin('sharedUsers', TType::LST, 6);
+      {
+        $output->writeListBegin(TType::STRING, count($this->sharedUsers));
+        {
+          foreach ($this->sharedUsers as $iter12)
+          {
+            $xfer += $output->writeString($iter12);
+          }
+        }
+        $output->writeListEnd();
+      }
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->sharedGroups !== null) {
+      if (!is_array($this->sharedGroups)) {
+        throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
+      }
+      $xfer += $output->writeFieldBegin('sharedGroups', TType::LST, 7);
+      {
+        $output->writeListBegin(TType::STRING, count($this->sharedGroups));
+        {
+          foreach ($this->sharedGroups as $iter13)
+          {
+            $xfer += $output->writeString($iter13);
+          }
+        }
+        $output->writeListEnd();
+      }
+      $xfer += $output->writeFieldEnd();
+    }
+    $xfer += $output->writeFieldStop();
+    $xfer += $output->writeStructEnd();
+    return $xfer;
+  }
+
+}
+
+class User {
+  static $_TSPEC;
+
+  public $userName = null;
+  public $groupList = null;
+
+  public function __construct($vals=null) {
+    if (!isset(self::$_TSPEC)) {
+      self::$_TSPEC = array(
+        1 => array(
+          'var' => 'userName',
+          'type' => TType::STRING,
+          ),
+        2 => array(
+          'var' => 'groupList',
+          'type' => TType::LST,
+          'etype' => TType::STRUCT,
+          'elem' => array(
+            'type' => TType::STRUCT,
+            'class' => '\Airavata\Model\Workspace\Group',
+            ),
+          ),
+        );
+    }
+    if (is_array($vals)) {
+      if (isset($vals['userName'])) {
+        $this->userName = $vals['userName'];
+      }
+      if (isset($vals['groupList'])) {
+        $this->groupList = $vals['groupList'];
+      }
+    }
+  }
+
+  public function getName() {
+    return 'User';
+  }
+
+  public function read($input)
+  {
+    $xfer = 0;
+    $fname = null;
+    $ftype = 0;
+    $fid = 0;
+    $xfer += $input->readStructBegin($fname);
+    while (true)
+    {
+      $xfer += $input->readFieldBegin($fname, $ftype, $fid);
+      if ($ftype == TType::STOP) {
+        break;
+      }
+      switch ($fid)
+      {
+        case 1:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->userName);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 2:
+          if ($ftype == TType::LST) {
+            $this->groupList = array();
+            $_size14 = 0;
+            $_etype17 = 0;
+            $xfer += $input->readListBegin($_etype17, $_size14);
+            for ($_i18 = 0; $_i18 < $_size14; ++$_i18)
+            {
+              $elem19 = null;
+              $elem19 = new \Airavata\Model\Workspace\Group();
+              $xfer += $elem19->read($input);
+              $this->groupList []= $elem19;
+            }
+            $xfer += $input->readListEnd();
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        default:
+          $xfer += $input->skip($ftype);
+          break;
+      }
+      $xfer += $input->readFieldEnd();
+    }
+    $xfer += $input->readStructEnd();
+    return $xfer;
+  }
+
+  public function write($output) {
+    $xfer = 0;
+    $xfer += $output->writeStructBegin('User');
+    if ($this->userName !== null) {
+      $xfer += $output->writeFieldBegin('userName', TType::STRING, 1);
+      $xfer += $output->writeString($this->userName);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->groupList !== null) {
+      if (!is_array($this->groupList)) {
+        throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
+      }
+      $xfer += $output->writeFieldBegin('groupList', TType::LST, 2);
+      {
+        $output->writeListBegin(TType::STRUCT, count($this->groupList));
+        {
+          foreach ($this->groupList as $iter20)
+          {
+            $xfer += $iter20->write($output);
+          }
+        }
+        $output->writeListEnd();
+      }
+      $xfer += $output->writeFieldEnd();
+    }
+    $xfer += $output->writeFieldStop();
+    $xfer += $output->writeStructEnd();
+    return $xfer;
+  }
+
+}
+
+class Gateway {
+  static $_TSPEC;
+
+  public $gatewayId = null;
+  public $gatewayName = null;
+  public $domain = null;
+  public $emailAddress = null;
+
+  public function __construct($vals=null) {
+    if (!isset(self::$_TSPEC)) {
+      self::$_TSPEC = array(
+        1 => array(
+          'var' => 'gatewayId',
+          'type' => TType::STRING,
+          ),
+        2 => array(
+          'var' => 'gatewayName',
+          'type' => TType::STRING,
+          ),
+        3 => array(
+          'var' => 'domain',
+          'type' => TType::STRING,
+          ),
+        4 => array(
+          'var' => 'emailAddress',
+          'type' => TType::STRING,
+          ),
+        );
+    }
+    if (is_array($vals)) {
+      if (isset($vals['gatewayId'])) {
+        $this->gatewayId = $vals['gatewayId'];
+      }
+      if (isset($vals['gatewayName'])) {
+        $this->gatewayName = $vals['gatewayName'];
+      }
+      if (isset($vals['domain'])) {
+        $this->domain = $vals['domain'];
+      }
+      if (isset($vals['emailAddress'])) {
+        $this->emailAddress = $vals['emailAddress'];
+      }
+    }
+  }
+
+  public function getName() {
+    return 'Gateway';
+  }
+
+  public function read($input)
+  {
+    $xfer = 0;
+    $fname = null;
+    $ftype = 0;
+    $fid = 0;
+    $xfer += $input->readStructBegin($fname);
+    while (true)
+    {
+      $xfer += $input->readFieldBegin($fname, $ftype, $fid);
+      if ($ftype == TType::STOP) {
+        break;
+      }
+      switch ($fid)
+      {
+        case 1:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->gatewayId);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 2:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->gatewayName);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 3:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->domain);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 4:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->emailAddress);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        default:
+          $xfer += $input->skip($ftype);
+          break;
+      }
+      $xfer += $input->readFieldEnd();
+    }
+    $xfer += $input->readStructEnd();
+    return $xfer;
+  }
+
+  public function write($output) {
+    $xfer = 0;
+    $xfer += $output->writeStructBegin('Gateway');
+    if ($this->gatewayId !== null) {
+      $xfer += $output->writeFieldBegin('gatewayId', TType::STRING, 1);
+      $xfer += $output->writeString($this->gatewayId);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->gatewayName !== null) {
+      $xfer += $output->writeFieldBegin('gatewayName', TType::STRING, 2);
+      $xfer += $output->writeString($this->gatewayName);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->domain !== null) {
+      $xfer += $output->writeFieldBegin('domain', TType::STRING, 3);
+      $xfer += $output->writeString($this->domain);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->emailAddress !== null) {
+      $xfer += $output->writeFieldBegin('emailAddress', TType::STRING, 4);
+      $xfer += $output->writeString($this->emailAddress);
+      $xfer += $output->writeFieldEnd();
+    }
+    $xfer += $output->writeFieldStop();
+    $xfer += $output->writeStructEnd();
+    return $xfer;
+  }
+
+}
+
+

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/app/libraries/AiravataClientFactory.php
----------------------------------------------------------------------
diff --git a/app/libraries/AiravataClientFactory.php b/app/libraries/AiravataClientFactory.php
new file mode 100755
index 0000000..c55a359
--- /dev/null
+++ b/app/libraries/AiravataClientFactory.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace Airavata\Client;
+
+$GLOBALS['THRIFT_ROOT'] = 'Thrift/';
+//require_once $GLOBALS['THRIFT_ROOT'] . 'Thrift.php';
+/*
+require_once $GLOBALS['THRIFT_ROOT'] . 'Transport/TTransport.php';
+require_once $GLOBALS['THRIFT_ROOT'] . 'Transport/TSocket.php';
+require_once $GLOBALS['THRIFT_ROOT'] . 'Protocol/TProtocol.php';
+require_once $GLOBALS['THRIFT_ROOT'] . 'Protocol/TBinaryProtocol.php';
+require_once $GLOBALS['THRIFT_ROOT'] . 'Exception/TException.php';
+require_once $GLOBALS['THRIFT_ROOT'] . 'Exception/TTransportException.php';
+require_once $GLOBALS['THRIFT_ROOT'] . 'Type/TType.php';
+require_once $GLOBALS['THRIFT_ROOT'] . 'Type/TMessageType.php';
+require_once $GLOBALS['THRIFT_ROOT'] . 'Factory/TStringFuncFactory.php';
+require_once $GLOBALS['THRIFT_ROOT'] . 'StringFunc/TStringFunc.php';
+require_once $GLOBALS['THRIFT_ROOT'] . 'StringFunc/Core.php';
+
+$GLOBALS['AIRAVATA_ROOT'] = 'Airavata/';
+require_once $GLOBALS['AIRAVATA_ROOT'] . 'API/Airavata.php';
+*/
+
+use Thrift\Protocol\TBinaryProtocol;
+use Thrift\Transport\TSocket;
+use Airavata\API\AiravataClient;
+
+class AiravataClientFactory
+{
+
+    private $airavataServerHost;
+    private $airavataServerPort;
+
+    public function __construct($options)
+    {
+        $this->airavataServerHost = isset($options['airavataServerHost']) ? $options['airavataServerHost'] : null;
+        $this->airavataServerPort = isset($options['airavataServerPort']) ? $options['airavataServerPort'] : null;
+    }
+
+    public function getAiravataClient()
+    {
+        $transport = new TSocket($this->airavataServerHost, $this->airavataServerPort);
+        $protocol = new TBinaryProtocol($transport);
+	$transport->open();
+        return new AiravataClient($protocol);
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/app/libraries/AppUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/AppUtilities.php b/app/libraries/AppUtilities.php
new file mode 100644
index 0000000..2f9b32e
--- /dev/null
+++ b/app/libraries/AppUtilities.php
@@ -0,0 +1,230 @@
+<?php
+
+//Airavata classes - loaded from app/libraries/Airavata
+use Airavata\API\AiravataClient;
+
+use Airavata\Model\AppCatalog\AppInterface\DataType;
+use Airavata\Model\AppCatalog\AppInterface\InputDataObjectType;
+use Airavata\Model\AppCatalog\AppInterface\OutputDataObjectType;
+use Airavata\Model\AppCatalog\AppInterface\ApplicationInterfaceDescription;
+
+use Airavata\Model\Workspace\Project;
+
+use Airavata\Model\AppCatalog\AppDeployment\ApplicationModule;
+use Airavata\Model\AppCatalog\AppDeployment\ApplicationParallelismType;
+use Airavata\Model\AppCatalog\AppDeployment\ApplicationDeploymentDescription;
+use Airavata\Model\AppCatalog\AppDeployment\SetEnvPaths;
+
+//use Airavata\Model\AppCatalog\ComputeResource
+
+
+class AppUtilities{
+
+	public static function create_or_update_appModule( $inputs, $update = false){
+
+		$airavataclient = Session::get("airavataClient");
+
+		$appModule = new ApplicationModule( array(
+												"appModuleName" => $inputs["appModuleName"],
+												"appModuleVersion" => $inputs["appModuleVersion"],
+												"appModuleDescription" => $inputs["appModuleDescription"]
+										));
+		
+		if( $update)
+			return $airavataclient->updateApplicationModule( $inputs["appModuleId"], $appModule);
+		else
+			return $airavataclient->registerApplicationModule( Session::get("gateway_id"), $appModule);
+	}
+
+	public static function deleteAppModule( $appModuleId){
+
+		$airavataclient = Session::get("airavataClient");
+
+		return $airavataclient->deleteApplicationModule( $appModuleId);
+	}
+
+	public static function getAppInterfaceData(){
+
+		$airavataclient = Session::get("airavataClient");
+
+		$dataType = new DataType();
+		$modules = AppUtilities::getAllModules();
+		$appInterfaces = $airavataclient->getAllApplicationInterfaces( Session::get("gateway_id"));
+
+
+		$InputDataObjectType = new InputDataObjectType();
+
+		return array(
+						"appInterfaces" 	=> $appInterfaces,
+						"dataTypes" 		=> $dataType::$__names,
+						"modules"   		=> $modules
+						);
+	}
+
+	public static function create_or_update_appInterface( $appInterfaceValues, $update = false){
+		
+		$airavataclient = Session::get("airavataClient");
+		//var_dump( $appInterfaceValues); exit;
+		$appInterface = new ApplicationInterfaceDescription( array(
+																"applicationName" => $appInterfaceValues["applicationName"],
+																"applicationDescription" => $appInterfaceValues["applicationDescription"],
+																"applicationModules" => $appInterfaceValues["applicationModules"]
+															) ); 
+
+		if( isset( $appInterfaceValues["inputName"]))
+		{
+			foreach ($appInterfaceValues["inputName"] as $index => $name) {
+				$inputDataObjectType = new InputDataObjectType( array(
+																	"name" => $name,
+																	"value" => $appInterfaceValues["inputValue"][ $index],
+																	"type" => $appInterfaceValues["inputType"][ $index],
+																	"applicationArgument" => $appInterfaceValues["applicationArgumentInput"][$index],
+																	"standardInput" => $appInterfaceValues["standardInput"][ $index],
+																	"userFriendlyDescription" => $appInterfaceValues["userFriendlyDescription"][ $index],
+																	"metaData" => $appInterfaceValues["metaData"][ $index],
+																	"inputOrder" => intval( $appInterfaceValues["inputOrder"][ $index]),
+																	"dataStaged" => intval( $appInterfaceValues["dataStaged"][ $index]),
+																	"isRequired" => $appInterfaceValues["isRequiredInput"][ $index],
+																	"requiredToAddedToCommandLine" => $appInterfaceValues["requiredToAddedToCommandLineInput"][$index]
+																) );
+				$appInterface->applicationInputs[] = $inputDataObjectType;
+			}
+		}
+
+		if( isset( $appInterfaceValues["outputName"]))
+		{
+			foreach ( $appInterfaceValues["outputName"] as $index => $name) {
+				$outputDataObjectType = new OutputDataObjectType( array(
+																	"name" => $name,
+																	"value" => $appInterfaceValues["outputValue"][ $index],
+																	"type" => $appInterfaceValues["outputType"][ $index],
+																	"applicationArgument" => $appInterfaceValues["applicationArgumentOutput"][$index],
+																	"dataMovement" => intval( $appInterfaceValues["dataMovement"][ $index]),
+																	"location" => $appInterfaceValues["location"][ $index],
+																	"isRequired" => $appInterfaceValues["isRequiredOutput"][ $index],
+																	"requiredToAddedToCommandLine" => $appInterfaceValues["requiredToAddedToCommandLineOutput"][$index],
+																	"searchQuery" => $appInterfaceValues["searchQuery"][$index]
+																));
+				$appInterface->applicationOutputs[] = $outputDataObjectType;
+			}
+		}
+
+		//var_dump( $appInterface); exit;
+
+		if( $update)
+			$airavataclient->updateApplicationInterface( $appInterfaceValues["app-interface-id"], $appInterface);
+		else
+			$airavataclient->getApplicationInterface($airavataclient->registerApplicationInterface( Session::get("gateway_id"), $appInterface) );
+
+		//print_r( "App interface has been created.");
+	}
+
+	public static function deleteAppInterface( $appInterfaceId){
+
+		$airavataclient = Session::get("airavataClient");
+
+		return $airavataclient->deleteApplicationInterface( $appInterfaceId);
+	}
+
+
+	public static function getAppDeploymentData(){
+
+		$airavataclient = Session::get("airavataClient");
+
+		$appDeployments = $airavataclient->getAllApplicationDeployments( Session::get("gateway_id"));
+		//var_dump( $appDeployments); exit;
+		$computeResources = $airavataclient->getAllComputeResourceNames();
+		$modules = AppUtilities::getAllModules();
+		$apt = new ApplicationParallelismType();
+
+		return array( 
+						"appDeployments" 			  => $appDeployments,
+						"applicationParallelismTypes" => $apt::$__names,
+						"computeResources"            => $computeResources,
+						"modules"			          => $modules
+					);
+	}
+
+	public static function create_or_update_appDeployment( $inputs, $update = false){
+
+		$appDeploymentValues = $inputs;
+
+		$airavataclient = Session::get("airavataClient");
+
+		if( isset( $appDeploymentValues["moduleLoadCmds"]))
+			$appDeploymentValues["moduleLoadCmds"] = array_unique( array_filter( $appDeploymentValues["moduleLoadCmds"]));
+
+		if( isset( $appDeploymentValues["libraryPrependPathName"] )) 
+		{	
+			$libPrependPathNames = array_unique( array_filter( $appDeploymentValues["libraryPrependPathName"],"trim" ));
+		
+			foreach( $libPrependPathNames as $index => $prependName)
+			{
+				$envPath = new SetEnvPaths(array(
+												"name" => $prependName,
+												"value" => $appDeploymentValues["libraryPrependPathValue"][ $index]
+											));
+				$appDeploymentValues["libPrependPaths"][] = $envPath;
+			}
+		}
+
+		if( isset( $appDeploymentValues["libraryAppendPathName"] )) 
+		{
+			$libAppendPathNames = array_unique( array_filter( $appDeploymentValues["libraryAppendPathName"],"trim" ));
+			foreach( $libAppendPathNames as $index => $appendName)
+			{
+				$envPath = new SetEnvPaths(array(
+												"name" => $appendName,
+												"value" => $appDeploymentValues["libraryAppendPathValue"][ $index]
+											));
+				$appDeploymentValues["libAppendPaths"][] = $envPath;
+			}
+		}
+
+		if( isset( $appDeploymentValues["environmentName"] )) 
+		{
+			$environmentNames = array_unique( array_filter( $appDeploymentValues["environmentName"], "trim"));
+			foreach( $environmentNames as $index => $envName)
+			{
+				$envPath = new SetEnvPaths(array(
+												"name" => $envName,
+												"value" => $appDeploymentValues["environmentValue"][$index]
+											));
+				$appDeploymentValues["setEnvironment"][] = $envPath;
+			}
+		}
+		
+		if( isset( $appDeploymentValues["preJobCommand"] )) 
+		{
+			$appDeploymentValues["preJobCommands"] = array_unique( array_filter( $appDeploymentValues["preJobCommand"], "trim"));
+		}
+
+		if( isset( $appDeploymentValues["postJobCommand"] )) 
+		{
+			$appDeploymentValues["postJobCommands"] = array_unique( array_filter( $appDeploymentValues["postJobCommand"], "trim"));
+		}
+
+		//var_dump( $appDeploymentValues); exit;
+		$appDeployment = new ApplicationDeploymentDescription(  $appDeploymentValues);
+		if( $update)
+			$airavataclient->updateApplicationDeployment( $inputs["app-deployment-id"], $appDeployment);
+		else
+			$appDeploymentId = $airavataclient->registerApplicationDeployment( Session::get("gateway_id"), $appDeployment);
+
+		return;
+
+	}
+
+	public static function deleteAppDeployment( $appDeploymentId )
+	{
+
+		$airavataclient = Session::get("airavataClient");
+
+		return $airavataclient->deleteApplicationDeployment( $appDeploymentId);
+	}
+
+	public static function getAllModules(){
+		$airavataclient = Session::get("airavataClient");
+		return $airavataclient->getAllAppModules( Session::get("gateway_id"));
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/app/libraries/CRUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/CRUtilities.php b/app/libraries/CRUtilities.php
new file mode 100644
index 0000000..8f55099
--- /dev/null
+++ b/app/libraries/CRUtilities.php
@@ -0,0 +1,459 @@
+<?php
+
+
+//Airavata classes - loaded from app/libraries/Airavata
+use Airavata\API\AiravataClient;
+
+//Compute Resource classes
+
+use Airavata\Model\AppCatalog\ComputeResource\FileSystems;
+use Airavata\Model\AppCatalog\ComputeResource\JobSubmissionInterface;
+use Airavata\Model\AppCatalog\ComputeResource\JobSubmissionProtocol;
+use Airavata\Model\AppCatalog\ComputeResource\SecurityProtocol;
+use Airavata\Model\AppCatalog\ComputeResource\ResourceJobManager;
+use Airavata\Model\AppCatalog\ComputeResource\ResourceJobManagerType;
+use Airavata\Model\AppCatalog\ComputeResource\JobManagerCommand;
+use Airavata\Model\AppCatalog\ComputeResource\DataMovementProtocol;
+use Airavata\Model\AppCatalog\ComputeResource\ComputeResourceDescription;
+use Airavata\Model\AppCatalog\ComputeResource\SSHJobSubmission;
+use Airavata\Model\AppCatalog\ComputeResource\LOCALSubmission;
+use Airavata\Model\AppCatalog\ComputeResource\UnicoreJobSubmission;
+use Airavata\Model\AppCatalog\ComputeResource\BatchQueue;
+use Airavata\Model\AppCatalog\ComputeResource\SCPDataMovement;
+use Airavata\Model\AppCatalog\ComputeResource\GridFTPDataMovement;
+use Airavata\Model\AppCatalog\ComputeResource\LOCALDataMovement;
+use Airavata\Model\AppCatalog\ComputeResource\UnicoreDataMovement;
+use Airavata\Model\AppCatalog\ComputeResource\MonitorMode;
+
+
+//Gateway Classes
+
+use Airavata\Model\AppCatalog\GatewayProfile\GatewayResourceProfile;
+use Airavata\Model\AppCatalog\GatewayProfile\ComputeResourcePreference;
+
+
+
+
+class CRUtilities{
+/**
+ * Basic utility functions
+ */
+
+//define('ROOT_DIR', __DIR__);
+
+/**
+ * Define configuration constants
+ */
+public static function register_or_update_compute_resource( $computeDescription, $update = false)
+{
+    $airavataclient = Session::get("airavataClient");
+    if( $update)
+    {
+        $computeResourceId = $computeDescription->computeResourceId;
+
+        if( $airavataclient->updateComputeResource( $computeResourceId, $computeDescription) )
+        {
+            $computeResource = $airavataclient->getComputeResource( $computeResourceId);
+            return $computeResource;
+        }
+        else
+            print_r( "Something went wrong while updating!"); exit;
+    }
+    else
+    {
+        /*
+        $fileSystems = new FileSystems();
+        foreach( $fileSystems as $fileSystem)
+            $computeDescription["fileSystems"][$fileSystem] = "";
+        */
+        $cd = new ComputeResourceDescription( $computeDescription);
+        $computeResourceId = $airavataclient->registerComputeResource( $cd);
+    }
+
+    $computeResource = $airavataclient->getComputeResource( $computeResourceId);
+    return $computeResource;
+
+}
+
+/*
+ * Getting data for Compute resource inputs 
+*/
+
+public static function getEditCRData(){
+    $files = new FileSystems();
+    $jsp = new JobSubmissionProtocol();
+    $rjmt = new ResourceJobManagerType();
+    $sp = new SecurityProtocol();
+    $dmp = new DataMovementProtocol();
+    $jmc = new JobManagerCommand();
+    $mm = new MonitorMode();
+    return array(
+                    "fileSystemsObject" => $files,
+                    "fileSystems" => $files::$__names,
+                    "jobSubmissionProtocolsObject" => $jsp,
+                    "jobSubmissionProtocols" => $jsp::$__names,
+                    "resourceJobManagerTypesObject" => $rjmt,
+                    "resourceJobManagerTypes" => $rjmt::$__names,
+                    "securityProtocolsObject" => $sp,
+                    "securityProtocols" => $sp::$__names,
+                    "dataMovementProtocolsObject" => $dmp,
+                    "dataMovementProtocols" => $dmp::$__names,
+                    "jobManagerCommands" => $jmc::$__names,
+                    "monitorModes" => $mm::$__names
+                );
+}
+
+
+public static function createQueueObject( $queue){
+    $queueObject = new BatchQueue( $queue); 
+    return $queueObject;
+}
+
+public static function deleteQueue( $computeResourceId, $queueName)
+{
+    $airavataclient = Session::get("airavataClient");
+    $airavataclient->deleteBatchQueue( $computeResourceId, $queueName);
+}
+
+
+/*
+ * Creating Job Submission Interface.
+*/
+
+public static function create_or_update_JSIObject( $inputs, $update = false){
+
+    $airavataclient = Session::get("airavataClient");
+    $computeResource = Utilities::get_compute_resource(  $inputs["crId"]);
+
+
+    $jsiId = null;
+    if( isset( $inputs["jsiId"]))
+        $jsiId = $inputs["jsiId"];
+
+    if( $inputs["jobSubmissionProtocol"] == JobSubmissionProtocol::LOCAL)
+    {
+
+        //print_r( $jsiObject->resourceJobManager->resourceJobManagerId);
+        $resourceManager = new ResourceJobManager(array( 
+                                                    "resourceJobManagerType" => $inputs["resourceJobManagerType"],
+                                                    "pushMonitoringEndpoint" => $inputs["pushMonitoringEndpoint"],
+                                                    "jobManagerBinPath"      => $inputs["jobManagerBinPath"],
+                                                    "jobManagerCommands"     => $inputs["jobManagerCommands"]
+                                                    ));
+
+        //$rmId = $jsiObject->resourceJobManager->resourceJobManagerId;
+        //$rm = $airavataclient->updateResourceJobManager($rmId, $resourceManager);
+        //print_r( $rm); exit;
+        $localJobSubmission = new LOCALSubmission(  array(
+                                                            "resourceJobManager" => $resourceManager
+                                                        )
+                                                    );
+
+        if( $update) //update Local JSP
+        {
+            $jsiObject = $airavataclient->getLocalJobSubmission( $jsiId);
+            $localSub = $airavataclient->updateResourceJobManager(  $jsiObject->resourceJobManager->resourceJobManagerId, $resourceManager);
+            //$localSub = $airavataclient->updateLocalSubmissionDetails( $jsiId, $localJobSubmission);
+        }
+        else        // create Local JSP
+        {
+            $localSub = $airavataclient->addLocalSubmissionDetails( $computeResource->computeResourceId, 0, $localJobSubmission);
+            return $localSub;
+        }
+        
+    }
+    else if( $inputs["jobSubmissionProtocol"] ==  JobSubmissionProtocol::SSH) /* SSH */
+    {
+        $resourceManager = new ResourceJobManager(array( 
+                                                    "resourceJobManagerType" => $inputs["resourceJobManagerType"],
+                                                    "pushMonitoringEndpoint" => $inputs["pushMonitoringEndpoint"],
+                                                    "jobManagerBinPath"      => $inputs["jobManagerBinPath"],
+                                                    "jobManagerCommands"     => $inputs["jobManagerCommands"]
+                                                    ));
+        $sshJobSubmission = new SSHJobSubmission( array
+                                                    (
+                                                        "securityProtocol" => intval( $inputs["securityProtocol"]),
+                                                        "resourceJobManager" => $resourceManager,
+                                                        "alternativeSSHHostName" => $inputs["alternativeSSHHostName"],
+                                                        "sshPort" => intval( $inputs["sshPort"] ),
+                                                        "monitorMode" => intval( $inputs["monitorMode"] )
+                                                    )
+                                                );
+        //var_dump( $sshJobSubmission); exit;
+        if( $update) //update Local JSP
+        {
+            $jsiObject = $airavataclient->getSSHJobSubmission( $jsiId);
+
+            //first update resource job manager
+            $rmjId = $jsiObject->resourceJobManager->resourceJobManagerId;
+            $airavataclient->updateResourceJobManager(  $rmjId, $resourceManager);
+            $jsiObject = $airavataclient->getSSHJobSubmission( $jsiId);
+
+            $jsiObject->securityProtocol = intval( $inputs["securityProtocol"] );
+            $jsiObject->alternativeSSHHostName = $inputs["alternativeSSHHostName"];
+            $jsiObject->sshPort = intval( $inputs["sshPort"] );
+            $jsiObject->monitorMode = intval( $inputs["monitorMode"] );
+            $jsiObject->resourceJobManager = $airavataclient->getresourceJobManager( $rmjId);
+            //var_dump( $jsiObject); exit;
+            //add updated resource job manager to ssh job submission object.
+            //$sshJobSubmission->resourceJobManager->resourceJobManagerId = $rmjId;
+            $localSub = $airavataclient->updateSSHJobSubmissionDetails( $jsiId, $jsiObject);
+        }
+        else
+        {
+            $sshSub = $airavataclient->addSSHJobSubmissionDetails( $computeResource->computeResourceId, 0, $sshJobSubmission);
+        }
+        return;        
+    }
+    else if( $inputs["jobSubmissionProtocol"] == JobSubmissionProtocol::UNICORE)
+    {
+        $unicoreJobSubmission  = new UnicoreJobSubmission( array
+                                                            (
+                                                                "securityProtocol" => intval( $inputs["securityProtocol"]),
+                                                                "unicoreEndPointURL" => $inputs["unicoreEndPointURL"]
+                                                            )
+                                                        );
+        if( $update)
+        {
+            $jsiObject = $airavataclient->getUnicoreJobSubmission( $jsiId);
+            $jsiObject->securityProtocol = intval( $inputs["securityProtocol"] );
+            $jsiObject->unicoreEndPointURL = $inputs["unicoreEndPointURL"];
+
+            $unicoreSub = $airavataclient->updateUnicoreJobSubmissionDetails( $jsiId, $jsiObject);
+        }
+        else
+        {
+            $unicoreSub = $airavataclient->addUNICOREJobSubmissionDetails( $computeResource->computeResourceId, 0, $unicoreJobSubmission);
+        }
+    }
+    else /* Globus does not work currently */
+    {
+        print_r( "Whoops! We haven't coded for this Job Submission Protocol yet. Still working on it. Please click <a href='" . URL::to('/') . "/cr/edit'>here</a> to go back to edit page for compute resource.");
+    }
+}
+
+/*
+ * Creating Data Movement Interface Object.
+*/
+public static function create_or_update_DMIObject( $inputs, $update = false){
+    $airavataclient = Session::get("airavataClient");
+
+    $computeResource = Utilities::get_compute_resource(  $inputs["crId"] );
+    if( $inputs["dataMovementProtocol"] == DataMovementProtocol::LOCAL) /* LOCAL */
+    {
+        $localDataMovement = new LOCALDataMovement();
+        $localdmp = $airavataclient->addLocalDataMovementDetails( $computeResource->computeResourceId, 0, $localDataMovement);
+        
+        if( $localdmp)
+            print_r( "The Local Data Movement has been added. Edit UI for the Local Data Movement Interface is yet to be made.
+                Please click <a href='" . URL::to('/') . "/cr/edit'>here</a> to go back to edit page for compute resource.");
+    }
+    else if( $inputs["dataMovementProtocol"] == DataMovementProtocol::SCP) /* SCP */
+    {
+        //var_dump( $inputs); exit;
+        $scpDataMovement = new SCPDataMovement( array(
+                                                "securityProtocol" => intval( $inputs["securityProtocol"] ),
+                                                "alternativeSCPHostName" => $inputs["alternativeSSHHostName"],
+                                                "sshPort" => intval( $inputs["sshPort"] )
+                                                )
+
+                                            );
+
+        if( $update)
+            $scpdmp = $airavataclient->updateSCPDataMovementDetails( $inputs["dmiId"], $scpDataMovement);
+        else
+            $scpdmp = $airavataclient->addSCPDataMovementDetails( $computeResource->computeResourceId, 0, $scpDataMovement);   
+   }
+    else if( $inputs["dataMovementProtocol"] == DataMovementProtocol::GridFTP) /* GridFTP */
+    {
+        $gridFTPDataMovement = new GridFTPDataMovement( array(
+                "securityProtocol" => $inputs["securityProtocol"],
+                "gridFTPEndPoints" => $inputs["gridFTPEndPoints"]
+            ));
+        if( $update)
+            $gridftpdmp = $airavataclient->updateGridFTPDataMovementDetails( $inputs["dmiId"], $gridFTPDataMovement);
+        else
+            $gridftpdmp = $airavataclient->addGridFTPDataMovementDetails( $computeResource->computeResourceId, 0, $gridFTPDataMovement);
+    }
+    else if( $inputs["dataMovementProtocol"] == DataMovementProtocol::UNICORE_STORAGE_SERVICE) /* Unicore Storage Service */
+    {
+        $unicoreDataMovement  = new UnicoreDataMovement( array
+                                                            (
+                                                                "securityProtocol" => intval( $inputs["securityProtocol"]),
+                                                                "unicoreEndPointURL" => $inputs["unicoreEndPointURL"]
+                                                            )
+                                                        );
+        if( $update)
+            $unicoredmp = $airavataclient->updateUnicoreDataMovementDetails( $inputs["dmiId"], $unicoreDataMovement);
+        else
+            $unicoredmp = $airavataclient->addUnicoreDataMovementDetails( $computeResource->computeResourceId, 0, $unicoreDataMovement);
+    }
+    else /* other data movement protocols */
+    {
+        print_r( "Whoops! We haven't coded for this Data Movement Protocol yet. Still working on it. Please click <a href='" . URL::to('/') . "/cr/edit'>here</a> to go back to edit page for compute resource.");
+    }
+}
+
+public static function getAllCRObjects( $onlyName = false){
+    $airavataclient = Session::get("airavataClient");
+    $crNames = $airavataclient->getAllComputeResourceNames();
+    if( $onlyName)
+        return $crNames;
+    else
+    {
+        $crObjects = array();
+        foreach( $crNames as $id => $crName)
+        {
+            $crObjects[] = $airavataclient->getComputeResource( $id);
+        }
+        return $crObjects;
+    }
+
+}
+
+public static function getBrowseCRData(){
+    $airavataclient = Session::get("airavataClient");
+	$appDeployments = $airavataclient->getAllApplicationDeployments( Session::get("gateway_id"));
+
+    return array( 'crObjects' => CRUtilities::getAllCRObjects(true),
+    			  'appDeployments' => $appDeployments 
+    			);
+}
+
+public static function getJobSubmissionDetails( $jobSubmissionInterfaceId, $jsp){
+    //jsp = job submission protocol type
+    $airavataclient = Session::get("airavataClient");
+    if( $jsp == JobSubmissionProtocol::LOCAL)
+        return $airavataclient->getLocalJobSubmission( $jobSubmissionInterfaceId);
+    else if( $jsp == JobSubmissionProtocol::SSH)
+        return $airavataclient->getSSHJobSubmission( $jobSubmissionInterfaceId);
+    else if( $jsp == JobSubmissionProtocol::UNICORE)
+        return $airavataclient->getUnicoreJobSubmission( $jobSubmissionInterfaceId);
+    else if( $jsp == JobSubmissionProtocol::CLOUD)
+        return $airavataclient->getCloudJobSubmission( $jobSubmissionInterfaceId);
+
+    //globus get function not present ??	
+}
+
+public static function getDataMovementDetails( $dataMovementInterfaceId, $dmi){
+    //jsp = job submission protocol type
+    $airavataclient = Session::get("airavataClient");
+    if( $dmi == DataMovementProtocol::LOCAL)
+        return $airavataclient->getLocalDataMovement( $dataMovementInterfaceId);
+    else if( $dmi == DataMovementProtocol::SCP)
+        return $airavataclient->getSCPDataMovement( $dataMovementInterfaceId);
+    else if( $dmi == DataMovementProtocol::GridFTP)
+        return $airavataclient->getGridFTPDataMovement( $dataMovementInterfaceId);
+    else if( $dmi == DataMovementProtocol::UNICORE_STORAGE_SERVICE)
+        return $airavataclient->getUnicoreDataMovement( $dataMovementInterfaceId);
+    /*
+    else if( $dmi == JobSubmissionProtocol::CLOUD)
+        return $airavataclient->getCloudJobSubmission( $dataMovementInterfaceId);
+    */
+
+    //globus get function not present ??
+}
+
+public static function deleteActions( $inputs){
+    $airavataclient = Session::get("airavataClient");
+    if( isset( $inputs["jsiId"]) )
+        if( $airavataclient->deleteJobSubmissionInterface( $inputs["crId"], $inputs["jsiId"]) )
+            return 1;
+        else
+            return 0;
+    else if( isset( $inputs["dmiId"]) )
+        if( $airavataclient->deleteDataMovementInterface( $inputs["crId"], $inputs["dmiId"]) )
+            return 1;
+        else 
+            return 0;
+    elseif( isset( $inputs["del-crId"]))
+    	if( $airavataclient->deleteComputeResource( $inputs["del-crId"] ) )
+    		return 1;
+    	else
+    		return 0;
+}
+
+public static function create_or_update_gateway_profile( $inputs, $update = false){
+    $airavataclient = Session::get("airavataClient");
+
+    $computeResourcePreferences = array();
+    if( isset( $input["crPreferences"]) )
+        $computeResourcePreferences = $input["crPreferences"];
+
+    $gatewayProfile = new GatewayResourceProfile( array(
+                                                        "gatewayName" => $inputs["gatewayName"],
+                                                        "gatewayDescription" => $inputs["gatewayDescription"],
+                                                        "computeResourcePreferences" =>  $computeResourcePreferences
+                                                        )
+                                                );
+
+    if( $update){
+        $gatewayProfile = new GatewayResourceProfile( array(
+                                                        "gatewayName" => $inputs["gatewayName"],
+                                                        "gatewayDescription" => $inputs["gatewayDescription"]
+                                                        )
+                                                );
+        $gatewayProfileId = $airavataclient->updateGatewayResourceProfile( $inputs["edit-gpId"], $gatewayProfile);
+    }
+    else
+        $gatewayProfileId = $airavataclient->registerGatewayResourceProfile( $gatewayProfile);
+}
+
+public static function getAllGatewayProfilesData(){
+    $airavataclient = Session::get("airavataClient");
+
+    if( Session::has("scigap_admin") )
+        $gateways = $airavataclient->getAllGateways();
+    else
+    {
+        $app_config = Utilities::read_config();
+        $gateways[0] = $airavataclient->getGateway( $app_config["gateway-id"]);
+    }
+
+    $gatewayProfiles = $airavataclient->getAllGatewayComputeResources();
+    //$gatewayProfileIds = array("GatewayTest3_57726e98-313f-4e7c-87a5-18e69928afb5", "GatewayTest4_4fd9fb28-4ced-4149-bdbd-1f276077dad8");
+    foreach( $gateways as $key => $gw)
+    {
+        $gateways[$key]->profile = array();
+        foreach( (array)$gatewayProfiles as $index => $gp)
+        {
+
+            if( $gw->gatewayId == $gp->gatewayID)
+            {
+                foreach( (array)$gp->computeResourcePreferences as $i => $crp)
+                {
+                    $gatewayProfiles[$index]->computeResourcePreferences[$i]->crDetails = $airavataclient->getComputeResource( $crp->computeResourceId);
+                }
+                $gateways[$key]->profile = $gatewayProfiles[$index];
+            }
+        }
+    }
+    //var_dump( $gatewayProfiles[0]->computeResourcePreferences[0]->crDetails); exit;
+    
+    return $gateways;
+}
+
+public static function add_or_update_CRP( $inputs){
+    $airavataclient = Session::get("airavataClient");
+
+    $computeResourcePreferences = new computeResourcePreference( $inputs);
+
+    //var_dump( $inputs); exit;
+    return $airavataclient->addGatewayComputeResourcePreference( $inputs["gatewayId"], $inputs["computeResourceId"], $computeResourcePreferences);
+
+}
+
+public static function deleteGP( $gpId){
+    $airavataclient = Session::get("airavataClient");
+
+    return $airavataclient->deleteGatewayResourceProfile( $gpId);
+}
+
+public static function deleteCR( $inputs){
+    $airavataclient = Session::get("airavataClient");
+
+    return $airavataclient->deleteGatewayComputeResourcePreference( $inputs["gpId"], $inputs["rem-crId"]);
+}
+
+}
+?>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/app/libraries/ExpUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/ExpUtilities.php b/app/libraries/ExpUtilities.php
new file mode 100644
index 0000000..40e5d36
--- /dev/null
+++ b/app/libraries/ExpUtilities.php
@@ -0,0 +1,996 @@
+<?php
+
+//Thrift classes - loaded from Vendor/Thrift
+use Thrift\Transport\TTransport;
+use Thrift\Exception\TException;
+use Thrift\Exception\TTransportException;
+use Thrift\Factory\TStringFuncFactory;
+use Thrift\Protocol\TBinaryProtocol;
+use Thrift\Transport\TSocket;
+
+//Airavata classes - loaded from app/libraries/Airavata
+use Airavata\API\AiravataClient;
+use Airavata\API\Error\InvalidRequestException;
+use Airavata\API\Error\AiravataClientException;
+use Airavata\API\Error\AiravataSystemException;
+use Airavata\API\Error\ExperimentNotFoundException;
+use Airavata\Model\Workspace\Experiment\ComputationalResourceScheduling;
+use Airavata\Model\AppCatalog\AppInterface\InputDataObjectType;
+use Airavata\Model\Workspace\Experiment\UserConfigurationData;
+use Airavata\Model\Workspace\Experiment\AdvancedOutputDataHandling;
+use Airavata\Model\Workspace\Experiment\Experiment;
+use Airavata\Model\Workspace\Experiment\ExperimentState;
+use Airavata\Model\AppCatalog\AppInterface\DataType;
+use Airavata\Model\Workspace\Experiment\JobState;
+use Airavata\Model\AppCatalog\ComputeResource\JobSubmissionInterface;
+use Airavata\Model\AppCatalog\ComputeResource\JobSubmissionProtocol;
+
+class ExpUtilities{
+
+/**
+ * Launch the experiment with the given ID
+ * @param $expId
+ */
+public static function launch_experiment($expId)
+{
+    $airavataclient = Session::get("airavataClient");
+    //global $tokenFilePath;
+    try
+    {
+        /* temporarily using hard-coded token
+        open_tokens_file($tokenFilePath);
+
+        $communityToken = $tokenFile->tokenId;
+
+
+        $token = isset($_SESSION['tokenId'])? $_SESSION['tokenId'] : $communityToken;
+
+        $airavataclient->launchExperiment($expId, $token);
+
+        $tokenString = isset($_SESSION['tokenId'])? 'personal' : 'community';
+
+        Utilities::print_success_message('Experiment launched using ' . $tokenString . ' allocation!');
+        */
+
+        $hardCodedToken = 'bdc612fe-401e-4684-88e9-317f99409c45';
+        $airavataclient->launchExperiment($expId, $hardCodedToken);
+
+        /*
+        Utilities::print_success_message('Experiment launched!');
+        Utilities::print_success_message("<p>Experiment launched!</p>" .
+            '<p>You will be redirected to the summary page shortly, or you can
+            <a href="experiment_summary.php?expId=' . $expId . '">go directly</a> to the experiment summary page.</p>');
+        redirect('experiment_summary.php?expId=' . $expId);
+        */
+    }
+    catch (InvalidRequestException $ire)
+    {
+        Utilities::print_error_message('<p>There was a problem launching the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>InvalidRequestException: ' . $ire->getMessage() . '</p>');
+    }
+    catch (ExperimentNotFoundException $enf)
+    {
+        Utilities::print_error_message('<p>There was a problem launching the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>ExperimentNotFoundException: ' . $enf->getMessage() . '</p>');
+    }
+    catch (AiravataClientException $ace)
+    {
+        Utilities::print_error_message('<p>There was a problem launching the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>AiravataClientException: ' . $ace->getMessage() . '</p>');
+    }
+    catch (AiravataSystemException $ase)
+    {
+        Utilities::print_error_message('<p>There was a problem launching the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>AiravataSystemException: ' . $ase->getMessage() . '</p>');
+    }
+    catch (Exception $e)
+    {
+        Utilities::print_error_message('<p>There was a problem launching the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>Exception: ' . $e->getMessage() . '</p>');
+    }
+}
+
+
+/**
+ * List the experiment's input files
+ * @param $experiment
+ */
+public static function list_input_files($experiment)
+{
+    $applicationInputs = Utilities::get_application_inputs($experiment->applicationId);
+
+    $experimentInputs = $experiment->experimentInputs;
+
+
+    //showing experiment inputs in the order defined by the admins.
+    $order = array();
+    foreach ($experimentInputs as $index => $input)
+    {
+        $order[$index] = $input->inputOrder;
+    }
+    array_multisort($order, SORT_ASC, $experimentInputs);
+    
+    foreach ($experimentInputs as $input)
+    {
+        $matchingAppInput = null;
+
+        foreach($applicationInputs as $applicationInput)
+        {
+            if ($input->name == $applicationInput->name)
+            {
+                $matchingAppInput = $applicationInput;
+            }
+        }
+        //var_dump($matchingAppInput);
+
+        if ($matchingAppInput->type == DataType::URI)
+        {
+            $explode = explode('/', $input->value);
+            echo '<p><a target="_blank"
+                        href="' . URL::to("/") . "/../../" . Constant::EXPERIMENT_DATA_ROOT . $explode[sizeof($explode)-2] . '/' . $explode[sizeof($explode)-1] . '">' .
+                $explode[sizeof($explode)-1] . '
+                <span class="glyphicon glyphicon-new-window"></span></a></p>';
+        }
+        elseif ($matchingAppInput->type == DataType::STRING)
+        {
+            echo '<p>' . $input->name . ': ' . $input->value . '</p>';
+        }
+    }
+}
+
+
+/**
+ * Get a list of the inputs for the application with the given ID
+ * @param $id
+ * @return null
+ */
+public static function get_application_inputs($id)
+{
+    $airavataclient = Session::get("airavataClient");
+    $inputs = null;
+
+    try
+    {
+        $inputs = $airavataclient->getApplicationInputs($id);
+    }
+    catch (InvalidRequestException $ire)
+    {
+        Utilities::print_error_message('<p>There was a problem getting application inputs.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>InvalidRequestException: ' . $ire->getMessage() . '</p>');
+    }
+    catch (AiravataClientException $ace)
+    {
+        Utilities::print_error_message('<p>There was a problem getting application inputs.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>Airavata Client Exception: ' . $ace->getMessage() . '</p>');
+    }
+    catch (AiravataSystemException $ase)
+    {
+        Utilities::print_error_message('<p>There was a problem getting application inputs.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>Airavata System Exception: ' . $ase->getMessage() . '</p>');
+    }
+
+    return $inputs;
+}
+
+
+/**
+ * Get a list of the outputs for the application with the given ID
+ * @param $id
+ * @return null
+ */
+public static function get_application_outputs($id)
+{
+    $airavataclient = Session::get("airavataClient");
+    $outputs = null;
+
+    try
+    {
+        $outputs = $airavataclient->getApplicationOutputs($id);
+    }
+    catch (InvalidRequestException $ire)
+    {
+        Utilities::print_error_message('<p>There was a problem getting application outputs.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>InvalidRequestException: ' . $ire->getMessage() . '</p>');
+    }
+    catch (AiravataClientException $ace)
+    {
+        Utilities::print_error_message('<p>There was a problem getting application outputs.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>Airavata Client Exception: ' . $ace->getMessage() . '</p>');
+    }
+    catch (AiravataSystemException $ase)
+    {
+        Utilities::print_error_message('<p>There was a problem getting application outputs.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>Airavata System Exception: ' . $ase->getMessage() . '</p>');
+    }
+
+    return $outputs;
+}
+
+
+/**
+ * Get the experiment with the given ID
+ * @param $expId
+ * @return null
+ */
+public static function get_experiment($expId)
+{
+    $airavataclient = Session::get("airavataClient");
+
+    try
+    {
+        return $airavataclient->getExperiment($expId);
+    }
+    catch (InvalidRequestException $ire)
+    {
+        Utilities::print_error_message('<p>There was a problem getting the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>InvalidRequestException: ' . $ire->getMessage() . '</p>');
+    }
+    catch (ExperimentNotFoundException $enf)
+    {
+        Utilities::print_error_message('<p>There was a problem getting the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>ExperimentNotFoundException: ' . $enf->getMessage() . '</p>');
+    }
+    catch (AiravataClientException $ace)
+    {
+        Utilities::print_error_message('<p>There was a problem getting the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>AiravataClientException: ' . $ace->getMessage() . '</p>');
+    }
+    catch (AiravataSystemException $ase)
+    {
+        Utilities::print_error_message('<p>There was a problem getting the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>AiravataSystemException: ' . $ase->getMessage() . '</p>');
+    }
+    catch (TTransportException $tte)
+    {
+        Utilities::print_error_message('<p>There was a problem getting the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>TTransportException: ' . $tte->getMessage() . '</p>');
+    }
+    catch (Exception $e)
+    {
+        Utilities::print_error_message('<p>There was a problem getting the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>Exception: ' . $e->getMessage() . '</p>');
+    }
+
+}
+
+
+
+/**
+ * Create and configure a new Experiment
+ * @return Experiment
+ */
+public static function assemble_experiment()
+{
+    $utility = new Utilities();
+    $experimentInputs = array();
+
+    $scheduling = new ComputationalResourceScheduling();
+    $scheduling->totalCPUCount = $_POST['cpu-count'];
+    $scheduling->nodeCount = $_POST['node-count'];
+    $scheduling->queueName = $_POST['queue-name'];
+    //$scheduling->numberOfThreads = $_POST['threads'];
+    //$scheduling->queueName = 'normal';
+    $scheduling->wallTimeLimit = $_POST['wall-time'];
+    //$scheduling->totalPhysicalMemory = $_POST['memory'];
+    $scheduling->resourceHostId = $_POST['compute-resource'];
+
+    $userConfigData = new UserConfigurationData();
+    $userConfigData->computationalResourceScheduling = $scheduling;
+
+    $applicationInputs = Utilities::get_application_inputs($_POST['application']);
+    $experimentInputs = Utilities::process_inputs($applicationInputs, $experimentInputs);
+    //var_dump($experimentInputs);
+
+    if( Utilities::$experimentPath != null){
+        $advHandling = new AdvancedOutputDataHandling();
+
+        $advHandling->outputDataDir = str_replace( base_path() . Constant::EXPERIMENT_DATA_ROOT, Utilities::$pathConstant , Utilities::$experimentPath);
+        $userConfigData->advanceOutputDataHandling = $advHandling;
+    }
+
+    //TODO: replace constructor with a call to airvata to get a prepopulated experiment template
+    $experiment = new Experiment();
+
+    // required
+    $experiment->projectID = $_POST['project'];
+    $experiment->userName = Session::get( 'username');
+    $experiment->name = $_POST['experiment-name'];
+
+    // optional
+    $experiment->description = $_POST['experiment-description'];
+    $experiment->applicationId = $_POST['application'];
+    $experiment->userConfigurationData = $userConfigData;
+    $experiment->experimentInputs = $experimentInputs;
+    if( isset( $_POST["emailNotification"]))
+    {
+        $experiment->emailNotification = intval( $_POST["emailNotification"] );
+        $experiment->emailAddresses = array_unique( array_filter( $_POST["emailAddresses"], "trim") );
+    }
+
+    // adding default experiment outputs for now till prepoulated experiment template is not implemented.
+    $experiment->experimentOutputs = Utilities::get_application_outputs( $_POST["application"]);
+
+    if ($experimentInputs)
+    {
+        return $experiment;
+    }
+}
+
+/**
+ * @param $applicationInputs
+ * @param $experimentInputs
+ * @internal param $environmentPath
+ * @return array
+ */
+public static function process_inputs($applicationInputs, $experimentInputs)
+{
+    $utility = new Utilities();
+    $experimentAssemblySuccessful = true;
+    $newExperimentInputs = array();
+
+    //var_dump($_FILES);
+
+    if (sizeof($_FILES) > 0)
+    {
+        if (Utilities::file_upload_successful())
+        {
+            // construct unique path
+            do
+            {
+                Utilities::$experimentPath = base_path() . Constant::EXPERIMENT_DATA_ROOT . str_replace(' ', '', Session::get('username') ) . md5(rand() * time()) . '/';
+            }
+            while (is_dir( Utilities::$experimentPath)); // if dir already exists, try again
+
+            //var_dump( Utilities::$experimentPath ); exit;
+            // create upload directory
+            if (!mkdir( Utilities::$experimentPath))
+            {
+                Utilities::print_error_message('<p>Error creating upload directory!
+                    Please try again later or report a bug using the link in the Help menu.</p>');
+                $experimentAssemblySuccessful = false;
+            }
+        }
+        else
+        {
+            $experimentAssemblySuccessful = false;
+        }
+    }
+
+    //sending application inputs in the order defined by the admins.
+    $order = array();
+    foreach ($applicationInputs as $index => $input)
+    {
+        $order[$index] = $input->inputOrder;
+    }
+    array_multisort($order, SORT_ASC, $applicationInputs);
+    
+    foreach ($applicationInputs as $applicationInput)
+    {
+        $experimentInput = new InputDataObjectType();
+        $experimentInput = $applicationInput;
+        //$experimentInput->name = $applicationInput->name;
+        //$experimentInput->metaData = $applicationInput->metaData;
+
+
+        //$experimentInput->type = $applicationInput->type;
+        //$experimentInput->type = DataType::STRING;
+
+
+        if(($applicationInput->type == DataType::STRING) ||
+            ($applicationInput->type == DataType::INTEGER) ||
+            ($applicationInput->type == DataType::FLOAT))
+        {
+            if (isset($_POST[$applicationInput->name]) && (trim($_POST[$applicationInput->name]) != ''))
+            {
+                $experimentInput->value = $_POST[$applicationInput->name];
+                $experimentInput->type = $applicationInput->type;
+
+            }
+            else // use previous value
+            {
+                $index = -1;
+                for ($i = 0; $i < sizeof($experimentInputs); $i++)
+                {
+                    if ($experimentInputs[$i]->name == $applicationInput->name)
+                    {
+                        $index = $i;
+                    }
+                }
+
+                if ($index >= 0)
+                {
+                    $experimentInput->value = $experimentInputs[$index]->value;
+                    $experimentInput->type = $applicationInput->type;
+                }
+            }
+        }
+        elseif ($applicationInput->type == DataType::URI)
+        {
+            //var_dump($_FILES[$applicationInput->name]->name);
+            if ($_FILES[$applicationInput->name]['name'])
+            {
+                $file = $_FILES[$applicationInput->name];
+
+
+                //
+                // move file to experiment data directory
+                //
+                $filePath = Utilities::$experimentPath . $file['name'];
+
+                // check if file already exists
+                if (is_file($filePath))
+                {
+                    unlink($filePath);
+
+                    Utilities::print_warning_message('Uploaded file already exists! Overwriting...');
+                }
+
+                $moveFile = move_uploaded_file($file['tmp_name'], $filePath);
+
+                if ($moveFile)
+                {
+                    Utilities::print_success_message('Upload: ' . $file['name'] . '<br>' .
+                        'Type: ' . $file['type'] . '<br>' .
+                        'Size: ' . ($file['size']/1024) . ' kB');//<br>' .
+                        //'Stored in: ' . $experimentPath . $file['name']);
+                }
+                else
+                {
+                    Utilities::print_error_message('<p>Error moving uploaded file ' . $file['name'] . '!
+                    Please try again later or report a bug using the link in the Help menu.</p>');
+                    $experimentAssemblySuccessful = false;
+                }
+
+                $experimentInput->value = str_replace(base_path() . Constant::EXPERIMENT_DATA_ROOT, Utilities::$pathConstant , $filePath);
+                $experimentInput->type = $applicationInput->type;
+                
+            }
+            else
+            {
+                $index = -1;
+                for ($i = 0; $i < sizeof($experimentInputs); $i++)
+                {
+                    if ($experimentInputs[$i]->name == $applicationInput->name)
+                    {
+                        $index = $i;
+                    }
+                }
+
+                if ($index >= 0)
+                {
+                    $experimentInput->value = $experimentInputs[$index]->value;
+                    $experimentInput->type = $applicationInput->type;
+                }
+            }
+
+        }
+        else
+        {
+            Utilities::print_error_message('I cannot accept this input type yet!');
+        }
+
+
+
+
+
+
+
+        //$experimentInputs[] = $experimentInput;
+        /*
+        $index = -1;
+        for ($i = 0; $i < sizeof($experimentInputs); $i++)
+        {
+            if ($experimentInputs[$i]->key == $experimentInput->key)
+            {
+                $index = $i;
+            }
+        }
+
+        if ($index >= 0)
+        {
+            unset($experimentInputs[$index]);
+        }
+        */
+        //$experimentInputs[] = $experimentInput;
+
+
+
+
+
+        $newExperimentInputs[] = $experimentInput;
+
+
+    }
+
+    if ($experimentAssemblySuccessful)
+    {
+        return $newExperimentInputs;
+    }
+    else
+    {
+        return false;
+    }
+
+}
+
+
+/**
+ * Check the uploaded files for errors
+ */
+public static function file_upload_successful()
+{
+    $uploadSuccessful = true;
+
+    foreach ($_FILES as $file)
+    {
+        //var_dump($file);
+        if($file['name'])
+        {
+            if ($file['error'] > 0)
+            {
+                $uploadSuccessful = false;
+                Utilities::print_error_message('<p>Error uploading file ' . $file['name'] . ' !
+                    Please try again later or report a bug using the link in the Help menu.');
+            }/*
+            elseif ($file['type'] != 'text/plain')
+            {
+                $uploadSuccessful = false;
+                Utilities::print_error_message('Uploaded file ' . $file['name'] . ' type not supported!');
+            }
+            elseif (($file['size'] / 1024) > 20)
+            {
+                $uploadSuccessful = false;
+                Utilities::print_error_message('Uploaded file ' . $file['name'] . ' must be smaller than 10 MB!');
+            }*/
+        }
+
+
+    }
+
+    return $uploadSuccessful;
+}
+
+
+/**
+ * Update the experiment with the given ID
+ * @param $expId
+ * @param $updatedExperiment
+ */
+public static function update_experiment($expId, $updatedExperiment)
+{
+    $airavataclient = Session::get("airavataClient");
+
+    try
+    {
+        $airavataclient->updateExperiment($expId, $updatedExperiment);
+
+        /*
+        Utilities::print_success_message("<p>Experiment updated!</p>" .
+            '<p>Click
+            <a href="' . URL::to('/') . '/experiment/summary?expId=' . $expId . '">here</a> to visit the experiment summary page.</p>');
+        */
+    }
+    catch (InvalidRequestException $ire)
+    {
+        Utilities::print_error_message('<p>There was a problem updating the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>InvalidRequestException: ' . $ire->getMessage() . '</p>');
+    }
+    catch (ExperimentNotFoundException $enf)
+    {
+        Utilities::print_error_message('<p>There was a problem updating the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>ExperimentNotFoundException: ' . $enf->getMessage() . '</p>');
+    }
+    catch (AiravataClientException $ace)
+    {
+        Utilities::print_error_message('<p>There was a problem updating the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>AiravataClientException: ' . $ace->getMessage() . '</p>');
+    }
+    catch (AiravataSystemException $ase)
+    {
+        Utilities::print_error_message('<p>There was a problem updating the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>AiravataSystemException: ' . $ase->getMessage() . '</p>');
+    }
+
+}
+
+
+/**
+ * Clone the experiment with the given ID
+ * @param $expId
+ */
+public static function clone_experiment($expId)
+{
+    $airavataclient = Session::get("airavataClient");
+
+    try
+    {
+        //create new experiment to receive the clone
+        $experiment = $airavataclient->getExperiment($expId);
+
+        $cloneId = $airavataclient->cloneExperiment($expId, 'Clone of ' . $experiment->name);
+
+        Utilities::print_success_message("<p>Experiment cloned!</p>" .
+            '<p>You will be redirected to the edit page shortly, or you can
+            <a href="edit_experiment.php?expId=' . $cloneId . '">go directly</a> to the edit experiment page.</p>');
+        //redirect('edit_experiment.php?expId=' . $cloneId);
+        return $cloneId;
+    }
+    catch (InvalidRequestException $ire)
+    {
+        Utilities::print_error_message('<p>There was a problem cloning the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>InvalidRequestException: ' . $ire->getMessage() . '</p>');
+    }
+    catch (ExperimentNotFoundException $enf)
+    {
+        Utilities::print_error_message('<p>There was a problem cloning the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>ExperimentNotFoundException: ' . $enf->getMessage() . '</p>');
+    }
+    catch (AiravataClientException $ace)
+    {
+        Utilities::print_error_message('<p>There was a problem cloning the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>AiravataClientException: ' . $ace->getMessage() . '</p>');
+    }
+    catch (AiravataSystemException $ase)
+    {
+        Utilities::print_error_message('<p>There was a problem cloning the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>AiravataSystemException: ' . $ase->getMessage() . '</p>');
+    }
+    catch (TTransportException $tte)
+    {
+        Utilities::print_error_message('<p>There was a problem cloning the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>TTransportException: ' . $tte->getMessage() . '</p>');
+    }
+}
+
+/**
+ * Cancel the experiment with the given ID
+ * @param $expId
+ */
+public static function cancel_experiment($expId)
+{
+    $airavataclient = Session::get("airavataClient");
+
+    try
+    {
+        $airavataclient->terminateExperiment($expId);
+
+        Utilities::print_success_message("Experiment canceled!");
+    }
+    catch (InvalidRequestException $ire)
+    {
+        Utilities::print_error_message('<p>There was a problem canceling the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>InvalidRequestException: ' . $ire->getMessage() . '</p>');
+    }
+    catch (ExperimentNotFoundException $enf)
+    {
+        Utilities::print_error_message('<p>There was a problem canceling the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>ExperimentNotFoundException: ' . $enf->getMessage() . '</p>');
+    }
+    catch (AiravataClientException $ace)
+    {
+        Utilities::print_error_message('<p>There was a problem canceling the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>AiravataClientException: ' . $ace->getMessage() . '</p>');
+    }
+    catch (AiravataSystemException $ase)
+    {
+        Utilities::print_error_message('<p>There was a problem canceling the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>AiravataSystemException: ' . $ase->getMessage() . '</p>');
+    }
+    catch (TTransportException $tte)
+    {
+        Utilities::print_error_message('<p>There was a problem canceling the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>TTransportException: ' . $tte->getMessage() . '</p>');
+    }
+    catch (Exception $e)
+    {
+        Utilities::print_error_message('<p>There was a problem canceling the experiment.
+            Please try again later or submit a bug report using the link in the Help menu.</p>' .
+            '<p>Exception: ' . $e->getMessage() . '</p>');
+    }
+}
+
+
+/**
+ * Create a new experiment from the values submitted in the form
+ * @return null
+ */
+public static function create_experiment()
+{
+    $airavataclient = Session::get("airavataClient");
+
+    $experiment = Utilities::assemble_experiment();
+    //var_dump($experiment); exit;
+    $expId = null;
+
+    try
+    {
+        if($experiment)
+        {
+            $expId = $airavataclient->createExperiment( Session::get("gateway_id"), $experiment);
+        }
+
+        if ($expId)
+        {
+            /*
+            Utilities::print_success_message("Experiment {$_POST['experiment-name']} created!" .
+                ' <a href="experiment_summary.php?expId=' . $expId . '">Go to experiment summary page</a>');
+            */
+        }
+        else
+        {
+            Utilities::print_error_message("Error creating experiment {$_POST['experiment-name']}!");
+        }
+    }
+    catch (InvalidRequestException $ire)
+    {
+        Utilities::print_error_message('InvalidRequestException!<br><br>' . $ire->getMessage());
+    }
+    catch (AiravataClientException $ace)
+    {
+        Utilities::print_error_message('AiravataClientException!<br><br>' . $ace->getMessage());
+    }
+    catch (AiravataSystemException $ase)
+    {
+        Utilities::print_error_message('AiravataSystemException!<br><br>' . $ase->getMessage());
+    }
+
+    return $expId;
+}
+
+/*
+ * Required in Experiment Sumamry page.
+ *
+*/
+
+public static function list_output_files($experiment, $expStatus)
+{
+    $expStatusVal = array_search($expStatus, ExperimentState::$__names);
+
+    if( $expStatusVal == ExperimentState::COMPLETED )
+    {
+        $utility = new Utilities();
+        $experimentOutputs = $experiment->experimentOutputs;
+        foreach ((array)$experimentOutputs as $output)
+        {
+            if ($output->type == DataType::URI || $output->type == DataType::STDOUT || $output->type == DataType::STDERR )
+            {
+                //echo '<p>' . $output->key .  ': <a href="' . $output->value . '">' . $output->value . '</a></p>';
+                $outputPath = str_replace(Utilities::$experimentDataPathAbsolute, Constant::EXPERIMENT_DATA_ROOT, $output->value);
+                $outputPathArray = explode("/", $outputPath);
+
+                echo '<p>' . $output->name  . ' : ' . '<a target="_blank"
+                            href="' . URL::to("/") . "/.." . str_replace(Utilities::$experimentDataPathAbsolute, Constant::EXPERIMENT_DATA_ROOT, $output->value) . '">' . 
+                            $outputPathArray[ sizeof( $outputPathArray) - 1] . ' <span class="glyphicon glyphicon-new-window"></span></a></p>';
+            }
+            elseif ($output->type == DataType::STRING)
+            {
+                echo '<p>' . $output->value . '</p>';
+            }
+        }
+    }
+    else
+        echo "Experiment hasn't completed. Experiment Status is : " . $expStatus;
+
+}
+public static function get_experiment_values( $experiment, $project, $forSearch = false)
+{
+    $airavataclient = Session::get("airavataClient");
+    //var_dump( $experiment); exit;
+    $expVal = array();
+    $expVal["experimentStatusString"] = "";
+    $expVal["experimentTimeOfStateChange"] = "";
+    $expVal["experimentCreationTime"] = "";
+
+    if( $experiment->experimentStatus != null)
+    {
+        $experimentStatus = $experiment->experimentStatus;
+        $experimentState = $experimentStatus->experimentState;
+        $experimentStatusString = ExperimentState::$__names[$experimentState];
+        $expVal["experimentStatusString"] = $experimentStatusString;
+        $expVal["experimentTimeOfStateChange"] = date('Y-m-d H:i:s', $experimentStatus->timeOfStateChange/1000); // divide by 1000 since timeOfStateChange is in ms
+        $expVal["experimentCreationTime"] = date('Y-m-d H:i:s', $experiment->creationTime/1000); // divide by 1000 since creationTime is in ms
+    }
+    $jobStatus = $airavataclient->getJobStatuses($experiment->experimentID);
+
+    if ($jobStatus)
+    {
+        $jobName = array_keys($jobStatus);
+        $jobState = JobState::$__names[$jobStatus[$jobName[0]]->jobState];
+    }
+    else
+    {
+        $jobState = null;
+    }
+
+    $expVal["jobState"] = $jobState;
+    
+    if(! $forSearch)
+    {
+        $userConfigData = $experiment->userConfigurationData;
+        $scheduling = $userConfigData->computationalResourceScheduling;
+        $expVal['scheduling'] = $scheduling;
+        $expVal["computeResource"] = Utilities::get_compute_resource($scheduling->resourceHostId);
+    }
+    $expVal["applicationInterface"] = Utilities::get_application_interface($experiment->applicationId);
+
+
+    switch ($experimentStatusString)
+    {
+        case 'CREATED':
+        case 'VALIDATED':
+        case 'SCHEDULED':
+        case 'CANCELED':
+        case 'FAILED':
+            $expVal["editable"] = true;
+            break;
+        default:
+            $expVal["editable"] = false;
+            break;
+    }
+
+    switch ($experimentStatusString)
+    {
+        case 'CREATED':
+        case 'VALIDATED':
+        case 'SCHEDULED':
+        case 'LAUNCHED':
+        case 'EXECUTING':
+            $expVal["cancelable"] = true;
+            break;
+        default:
+            $expVal["cancelable"] = false;
+            break;
+    }
+
+    return $expVal;
+
+}
+
+
+/**
+ * Get results of the user's search of experiments
+ * @return array|null
+ */
+public static function get_expsearch_results( $inputs)
+{
+    $airavataclient = Session::get("airavataClient");
+    $experiments = array();
+
+    try
+    {
+        switch ( $inputs["search-key"])
+        {
+            case 'experiment-name':
+                $experiments = $airavataclient->searchExperimentsByName(Session::get('gateway_id'), Session::get('username'), $inputs["search-value"]);
+                break;
+            case 'experiment-description':
+                $experiments = $airavataclient->searchExperimentsByDesc(Session::get('gateway_id'), Session::get('username'), $inputs["search-value"]);
+                break;
+            case 'application':
+                $experiments = $airavataclient->searchExperimentsByApplication(Session::get('gateway_id'), Session::get('username'), $inputs["search-value"]);
+                break;
+            case 'creation-time':
+                $experiments = $airavataclient->searchExperimentsByCreationTime(Session::get('gateway_id'), Session::get('username'), strtotime( $inputs["from-date"])*1000, strtotime( $inputs["to-date"])*1000 );
+                break;
+            case '':
+        }
+    }
+    catch (InvalidRequestException $ire)
+    {
+        Utilities::print_error_message('InvalidRequestException!<br><br>' . $ire->getMessage());
+    }
+    catch (AiravataClientException $ace)
+    {
+        Utilities::print_error_message('AiravataClientException!<br><br>' . $ace->getMessage());
+    }
+    catch (AiravataSystemException $ase)
+    {
+        if ($ase->airavataErrorType == 2) // 2 = INTERNAL_ERROR
+        {
+            Utilities::print_info_message('<p>You have not created any experiments yet, so no results will be returned!</p>
+                                <p>Click <a href="create_experiment.php">here</a> to create an experiment, or
+                                <a href="create_project.php">here</a> to create a new project.</p>');
+        }
+        else
+        {
+            Utilities::print_error_message('There was a problem with Airavata. Please try again later or report a bug using the link in the Help menu.');
+            //print_error_message('AiravataSystemException!<br><br>' . $ase->airavataErrorType . ': ' . $ase->getMessage());
+        }
+    }
+    catch (TTransportException $tte)
+    {
+        Utilities::print_error_message('TTransportException!<br><br>' . $tte->getMessage());
+    }
+
+    //get values of all experiments
+    $expContainer = array();
+    $expNum = 0;
+    foreach( $experiments as $experiment)
+    {
+        $expValue = Utilities::get_experiment_values( $experiment, Utilities::get_project($experiment->projectID), true );
+        $expContainer[$expNum]['experiment'] = $experiment;
+        if( $expValue["experimentStatusString"] == "FAILED")
+            $expValue["editable"] = false;
+        $expContainer[$expNum]['expValue'] = $expValue;
+        $expNum++;
+    }
+
+    return $expContainer;
+}
+
+public static function getExpStates(){
+    return ExperimentState::$__names;
+}
+
+
+public static function apply_changes_to_experiment($experiment, $input)
+{
+    $experiment->name = $input['experiment-name'];
+    $experiment->description = rtrim($input['experiment-description']);
+    $experiment->projectID = $input['project'];
+    //$experiment->applicationId = $_POST['application'];
+
+    $userConfigDataUpdated = $experiment->userConfigurationData;
+    $schedulingUpdated = $userConfigDataUpdated->computationalResourceScheduling;
+
+    $schedulingUpdated->resourceHostId = $input['compute-resource'];
+    $schedulingUpdated->nodeCount = $input['node-count'];
+    $schedulingUpdated->queueName = $_POST['queue-name'];
+    $schedulingUpdated->totalCPUCount = $input['cpu-count'];
+    $schedulingUpdated->wallTimeLimit = $input['wall-time'];
+
+    $userConfigDataUpdated->computationalResourceScheduling = $schedulingUpdated;
+    $experiment->userConfigurationData = $userConfigDataUpdated;
+
+
+
+
+    $applicationInputs = Utilities::get_application_inputs($experiment->applicationId);
+
+    $experimentInputs = $experiment->experimentInputs; // get current inputs
+    $experimentInputs = Utilities::process_inputs($applicationInputs, $experimentInputs); // get new inputs
+    
+    if ($experimentInputs)
+    {
+        $experiment->experimentInputs = $experimentInputs;
+        //var_dump($experiment);
+        return $experiment;
+    }
+}
+
+
+
+}
+
+?>