collection.h

00001 /***************************************************************
00002  *
00003  * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
00004  * University of Wisconsin-Madison, WI.
00005  * 
00006  * Licensed under the Apache License, Version 2.0 (the "License"); you
00007  * may not use this file except in compliance with the License.  You may
00008  * obtain a copy of the License at
00009  * 
00010  *    http://www.apache.org/licenses/LICENSE-2.0
00011  * 
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  *
00018  ***************************************************************/
00019 
00020 
00021 #ifndef __CLASSAD_COLLECTION_H__
00022 #define __CLASSAD_COLLECTION_H__
00023 
00024 #include "classad/view.h"
00025 #include "classad/source.h"
00026 #include "classad/sink.h"
00027 
00028 BEGIN_NAMESPACE( classad )
00029 
00030 
00031 class ClassAdCollectionInterface {
00032 public:
00033     ClassAdCollectionInterface( );
00034     virtual ~ClassAdCollectionInterface( );
00035 
00036     enum {
00037         ClassAdCollOp_NoOp                  = 10000,
00038 
00039         __ClassAdCollOp_ViewOps_Begin__,
00040         ClassAdCollOp_CreateSubView         = __ClassAdCollOp_ViewOps_Begin__,
00041         ClassAdCollOp_CreatePartition       ,
00042         ClassAdCollOp_DeleteView            ,
00043         ClassAdCollOp_SetViewInfo           ,
00044         ClassAdCollOp_AckViewOp             ,
00045         __ClassAdCollOp_ViewOps_End__       = ClassAdCollOp_AckViewOp,
00046 
00047         __ClassAdCollOp_ClassAdOps_Begin__,
00048         ClassAdCollOp_AddClassAd            =__ClassAdCollOp_ClassAdOps_Begin__,
00049         ClassAdCollOp_UpdateClassAd         ,
00050         ClassAdCollOp_ModifyClassAd         ,
00051         ClassAdCollOp_RemoveClassAd         ,
00052         ClassAdCollOp_AckClassAdOp          ,
00053         __ClassAdCollOp_ClassAdOps_End__    = ClassAdCollOp_AckClassAdOp,
00054 
00055         __ClassAdCollOp_XactionOps_Begin__,
00056         ClassAdCollOp_OpenTransaction       =__ClassAdCollOp_XactionOps_Begin__,
00057         ClassAdCollOp_AckOpenTransaction    ,
00058         ClassAdCollOp_CommitTransaction     ,
00059         ClassAdCollOp_AbortTransaction      ,
00060         ClassAdCollOp_AckCommitTransaction  ,
00061         ClassAdCollOp_ForgetTransaction     ,
00062         __ClassAdCollOp_XactionOps_End__    = ClassAdCollOp_ForgetTransaction,
00063 
00064         __ClassAdCollOp_ReadOps_Begin__     ,
00065         ClassAdCollOp_GetClassAd            = __ClassAdCollOp_ReadOps_Begin__,
00066         ClassAdCollOp_GetViewInfo           ,
00067         ClassAdCollOp_GetSubordinateViewNames,
00068         ClassAdCollOp_GetPartitionedViewNames,
00069         ClassAdCollOp_FindPartitionName     ,
00070         ClassAdCollOp_IsActiveTransaction   ,
00071         ClassAdCollOp_IsCommittedTransaction,
00072         ClassAdCollOp_GetAllActiveTransactions,
00073         ClassAdCollOp_GetAllCommittedTransactions,
00074         ClassAdCollOp_GetServerTransactionState,
00075         ClassAdCollOp_AckReadOp             ,
00076         __ClassAdCollOp_ReadOps_End__       = ClassAdCollOp_AckReadOp,
00077 
00078         __ClassAdCollOp_MiscOps_Begin__     ,
00079         ClassAdCollOp_Connect               = __ClassAdCollOp_MiscOps_Begin__,
00080         ClassAdCollOp_QueryView             ,
00081         ClassAdCollOp_Disconnect            ,
00082         __ClassAdCollOp_MiscOps_End__       = ClassAdCollOp_Disconnect,
00083                 ClassAdCollOp_CheckPoint
00084     };
00085 
00086     static const char * const CollOpStrings[];
00087 
00088     enum AckMode { _DEFAULT_ACK_MODE, WANT_ACKS, DONT_WANT_ACKS };
00089 
00090         // outcome from a commit
00091     enum { XACTION_ABORTED, XACTION_COMMITTED, XACTION_UNKNOWN };
00092 
00093         // Logfile control
00094     virtual bool InitializeFromLog( const std::string &filename,
00095                                     const std::string storagefile="", 
00096                                     const std::string checkpointfile="" ) = 0;
00097     virtual bool TruncateLog(void);
00098 
00099         // View creation/deletion/interrogation
00100     virtual bool CreateSubView( const ViewName &viewName,
00101                 const ViewName &parentViewName,
00102                 const std::string &constraint, const std::string &rank,
00103                 const std::string &partitionExprs ) = 0;
00104     virtual bool CreatePartition( const ViewName &viewName,
00105                 const ViewName &parentViewName,
00106                 const std::string &constraint, const std::string &rank,
00107                 const std::string &partitionExprs, ClassAd *rep ) = 0;
00108     virtual bool DeleteView( const ViewName &viewName ) = 0;
00109     virtual bool SetViewInfo( const ViewName &viewName, 
00110                 const std::string &constraint, const std::string &rank, 
00111                 const std::string &partitionAttrs ) = 0;
00112     virtual bool GetViewInfo( const ViewName &viewName, ClassAd *&viewInfo )=0;
00113         // Child view interrogation
00114     virtual bool GetSubordinateViewNames( const ViewName &viewName,
00115                 std::vector<std::string>& views ) = 0;
00116     virtual bool GetPartitionedViewNames( const ViewName &viewName,
00117                 std::vector<std::string>& views ) = 0;
00118     virtual bool FindPartitionName( const ViewName &viewName, ClassAd *rep, 
00119                 ViewName &partition ) = 0;
00120 
00121 
00122         // ClassAd manipulation 
00123     virtual bool AddClassAd( const std::string &key, ClassAd *newAd ) = 0;
00124     virtual bool UpdateClassAd( const std::string &key, ClassAd *updateAd ) = 0;
00125     virtual bool ModifyClassAd( const std::string &key, ClassAd *modifyAd ) = 0;
00126     virtual bool RemoveClassAd( const std::string &key ) = 0;
00127     virtual ClassAd *GetClassAd(const std::string &key ) = 0;
00128 
00129 
00130         // Mode management
00131     bool SetAcknowledgementMode( AckMode );
00132     AckMode GetAcknowledgementMode( ) const { return( amode ); }
00133 
00134 
00135         // Transaction management
00136     virtual bool OpenTransaction( const std::string &xactionName) = 0;
00137     bool SetCurrentTransaction( const std::string &xactionName );
00138     void GetCurrentTransaction( std::string &xactionName ) const;
00139     virtual bool CloseTransaction( const std::string &xactionName, bool commit,
00140                 int &outcome )=0;
00141 
00142     virtual bool IsMyActiveTransaction( const std::string &xactionName ) = 0;
00143     virtual void GetMyActiveTransactions( std::vector<std::string>& ) = 0;
00144     virtual bool IsActiveTransaction( const std::string &xactionName ) = 0;
00145     virtual bool GetAllActiveTransactions( std::vector<std::string>& ) = 0;
00146     virtual bool IsCommittedTransaction( const std::string &xactionName ) = 0;
00147     virtual bool GetAllCommittedTransactions( std::vector<std::string>& ) = 0;
00148 
00149 
00150         // misc
00151     static inline const char *GetOpString( int op ) {
00152         return( op>=ClassAdCollOp_NoOp && op<=__ClassAdCollOp_MiscOps_End__ ? 
00153                 CollOpStrings[op-ClassAdCollOp_NoOp] : "(unknown)" );
00154     }
00155 
00156 protected:
00157         // Utility functions to make collection log records
00158     ClassAd *_CreateSubView( const ViewName &viewName,
00159                 const ViewName &parentViewName,
00160                 const std::string &constraint, const std::string &rank,
00161                 const std::string &partitionExprs );
00162     ClassAd *_CreatePartition( const ViewName &viewName,
00163                 const ViewName &parentViewName,
00164                 const std::string &constraint, const std::string &rank,
00165                 const std::string &partitionExprs, ClassAd *rep );
00166     ClassAd *_DeleteView( const ViewName &viewName );
00167     ClassAd *_SetViewInfo( const ViewName &viewName, 
00168                 const std::string &constraint, const std::string &rank, 
00169                 const std::string &partitionAttrs );
00170     ClassAd *_AddClassAd( const std::string &xactionName, 
00171                 const std::string &key, ClassAd *newAd );
00172     ClassAd *_UpdateClassAd( const std::string &xactionName, 
00173                 const std::string &key, ClassAd *updateAd );
00174     ClassAd *_ModifyClassAd( const std::string &xactionName, 
00175                 const std::string &key, ClassAd *modifyAd );
00176     ClassAd *_RemoveClassAd( const std::string &xactionName,
00177                 const std::string &key );
00178 
00179         // mode management data
00180     AckMode         amode;
00181     std::string     currentXactionName;
00182 
00183         // function which executes log records in recovery mode
00184     virtual bool OperateInRecoveryMode( ClassAd* ) = 0;
00185 
00186         // utility functions to operate on logs and log metadata
00187     ClassAd         *ReadLogEntry( FILE * );
00188     bool            WriteLogEntry( FILE *, ClassAd *, bool sync=true );
00189     bool            ReadLogFile( );
00190     std::string     logFileName;
00191     ClassAdParser   parser;
00192     ClassAdUnParser unparser;
00193     FILE            *log_fp;
00194 
00195         std::string                  StorageFileName;
00196         int                     sfiled;
00197         // override for client and server
00198     virtual bool LogState( FILE * ) = 0;
00199 
00200 private:
00201     ClassAdCollectionInterface(const ClassAdCollectionInterface &)            { return;       }
00202     ClassAdCollectionInterface &operator=(const ClassAdCollectionInterface &) { return *this; }
00203 };
00204 
00205 
00206 END_NAMESPACE
00207 
00208 #endif
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends