1
/****************************************************************************
3
| Copyright (c) 2007 Novell, Inc.
6
| This program is free software; you can redistribute it and/or
7
| modify it under the terms of version 2 of the GNU General Public License as
8
| published by the Free Software Foundation.
10
| This program is distributed in the hope that it will be useful,
11
| but WITHOUT ANY WARRANTY; without even the implied warranty of
12
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
| GNU General Public License for more details.
15
| You should have received a copy of the GNU General Public License
16
| along with this program; if not, contact Novell, Inc.
18
| To contact Novell about this file by physical or electronic mail,
19
| you may find current contact information at www.novell.com
21
| Author: Ravi Kumar M <rkumar1@novell.com>
22
|***************************************************************************/
26
using System.Collections;
30
using System.Security.Cryptography;
31
using System.Security.Cryptography.X509Certificates;
32
using System.Diagnostics;
33
using System.Threading;
42
using Simias.Storage.Provider;
44
using Persist = Simias.Storage.Provider;
46
namespace Simias.Storage
49
/// This is the top level object for the Collection Store. The Store object can contain multiple
50
/// collection objects.
52
public class DataStore : IComparable
56
/// Object used to store free space available on Mount point.
58
public long AvailableFreeSpace;
61
/// Used to log messages.
63
static private readonly ISimiasLog log = SimiasLogManager.GetLogger( typeof( Store ) );
66
/// Object used to store the name of the Unmanaged path.
68
public string DataPath;
71
/// Object used to store the full path of the Unmanaged Path.
73
public string FullPath;
76
/// Object used to store the status of datapaths.
81
private const string apacheUser = "wwwrun";
84
private const string apacheGroup = "www";
95
public DataStore(string datapath,string fullpath,string enabled)
99
this.DataPath = datapath;
100
this.FullPath = fullpath;
101
string enable = "True";
102
UnixDriveInfo mntpt = new UnixDriveInfo(this.FullPath);
103
this.AvailableFreeSpace = mntpt.AvailableFreeSpace;
104
if( enabled.Equals( enable ) )
107
this.Enabled = false;
111
//Ignore if the Volume is not mounted.
118
public DataStore(string datapath,string fullpath,bool enabled)
122
this.DataPath = datapath;
123
this.FullPath = fullpath;
124
UnixDriveInfo mntpt = new UnixDriveInfo(this.FullPath);
125
this.AvailableFreeSpace = mntpt.AvailableFreeSpace;
126
this.Enabled = enabled;
130
//Ignore if the Volume is not mounted.
145
public DataStore(string datapath)
147
Store store = Store.GetStore();
148
this.DataPath = datapath;
149
this.FullPath = Store.StorePath;
150
UnixDriveInfo mntpt = new UnixDriveInfo(this.FullPath);
151
this.AvailableFreeSpace = mntpt.AvailableFreeSpace;
156
///Implementing CompareTo
158
public int CompareTo(Object obj)
160
DataStore compare = (DataStore)obj;
161
int result = this.AvailableFreeSpace.CompareTo(compare.AvailableFreeSpace);
166
/// Add a data store for an iFolder Server.
168
/// <returns>Bool true on success.</returns>
169
public int AddStore(string ServerID)
171
Store store = Store.GetStore();
172
Domain domain = store.GetDomain( store.DefaultDomain );
173
string storepath = Store.StorePath;
174
string tmppath = Path.Combine(storepath,"SimiasFiles");
175
tmppath = Path.Combine(tmppath,this.DataPath);
177
if( Directory.Exists( tmppath ) == true )
179
else if( Directory.Exists( this.FullPath ) != true )
181
else if( Execute( "chown", "-R {0}:{1} {2}", apacheUser, apacheGroup, this.FullPath ) != 0 )
184
Mono.Posix.Syscall.symlink(this.FullPath,tmppath);
186
string storageFormat = String.Format( "{0}|{1}", this.DataPath, this.FullPath);
187
storageFormat = String.Format( "{0}|{1}",storageFormat,this.Enabled.ToString());
188
HostNode host = HostNode.GetLocalHost();
189
host.Properties.AddProperty( PropertyTags.DataPath, storageFormat );
195
/// Modify data store for an iFolder Server.
197
/// <param name="name">The name of the data store.</param>
198
/// <returns>Bool true on success.</returns>
199
public bool ModifyStore( string datapath, bool enabled )
201
HostNode host = HostNode.GetLocalHost();
202
MultiValuedList mv = host.Properties.GetProperties( PropertyTags.DataPath );
204
foreach( Property prop in mv )
206
string[] comps = ( (string) prop.Value ).Split( '|' );
207
if( (datapath.Equals(comps[0])))
209
Store store = Store.GetStore();
210
Domain domain = store.GetDomain( store.DefaultDomain );
214
string storageFormat = String.Format( "{0}|{1}", comps[0], comps[1]);
215
storageFormat = String.Format( "{0}|{1}", storageFormat, enabled.ToString());
216
host.Properties.AddProperty( PropertyTags.DataPath, storageFormat );
226
/// Restrns the storepath based on the load on each volume
228
/// <returns>Storepath</returns>
229
public static DataStore[] GetVolumes()
231
HostNode host = HostNode.GetLocalHost();
234
MultiValuedList mv = host.Properties.GetProperties( PropertyTags.DataPath );
235
ArrayList VolumeList = new ArrayList();
239
foreach( Property prop in mv )
241
VolumeList.Add(prop.Value);
244
string[] stringArray = new string[VolumeList.Count];
245
VolumeList.CopyTo(stringArray);
246
DataStore[] DataStoreArray = new DataStore[VolumeList.Count+1];
247
DataStoreArray[0] = new DataStore("Default-Store");
248
foreach(string a in stringArray)
250
string[] comps = a.Split( '|' );
251
DataStoreArray[ count ] = new DataStore(comps[0],comps[1],comps[2]);
254
return DataStoreArray;
259
DataStore[] DataStoreArray = new DataStore[1];
260
DataStoreArray[0] = new DataStore("Default-Store");
261
return DataStoreArray;
266
/// Execute the command in the shell.
268
/// <param name="command">The command.</param>
269
/// <param name="format">The arguments of the command.</param>
270
/// <param name="args">The arguments for the format.</param>
271
/// <returns>The results of the command.</returns>
272
static int Execute(string command, string format, params object[] args)
274
ProcessStartInfo info = new ProcessStartInfo( command, String.Format( format, args ) ); Process p = Process.Start(info);