support for node API
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sun, 11 Sep 2005 12:39:24 +0000 (12:39 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sun, 11 Sep 2005 12:39:24 +0000 (12:39 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@116 8392b6e1-25fa-0310-8288-cc32f8e212ea

bin/BackupPC_updatedb
conf/config.pl

index 5c95dd0..12ac84a 100755 (executable)
@@ -41,12 +41,19 @@ my $beenThere = {};
 
 my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
 my $user = $Conf{SearchUser} || '';
-my $index_path = $Conf{HyperEstraierIndex};
-if ($index_path) {
-       $index_path = $TopDir . '/' . $index_path;
-       $index_path =~ s#//#/#g;
+
+my $use_hest = $Conf{HyperEstraierIndex};
+my ($index_path, $index_node_url);
+if ($use_hest) {
        use HyperEstraier;
+       if ($use_hest =~ m#^http://#) {
+               $index_node_url = $use_hest;
+       } else {
+               $index_path = $TopDir . '/' . $index_path;
+               $index_path =~ s#//#/#g;
+       }
 }
+print "-- $use_hest : $index_path OR $index_node_url --\n";
 
 
 my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
@@ -88,6 +95,7 @@ sub curr_time {
 }
 
 my $hest_db;
+my $hest_node;
 
 sub signal {
        my($sig) = @_;
@@ -106,6 +114,11 @@ sub hest_update {
 
        my ($host_id, $share_id, $num) = @_;
 
+       unless ($use_hest) {
+               print STDERR "HyperEstraier support not enabled in configuration\n";
+               return;
+       }
+
        print curr_time," updating HyperEstraier:";
 
        my $t = time();
@@ -113,10 +126,18 @@ sub hest_update {
        my $offset = 0;
        my $added = 0;
 
-       print " opening index $index_path";
-       $hest_db = HyperEstraier::Database->new();
-       $hest_db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);
-
+       print " opening index $use_hest";
+       if ($index_path) {
+               $hest_db = HyperEstraier::Database->new();
+               $hest_db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);
+               print " directly";
+       } elsif ($index_node_url) {
+               $hest_node ||= HyperEstraier::Node->new($index_node_url);
+               $hest_node->set_auth('admin', 'admin');
+               print " via node URL";
+       } else {
+               die "don't know how to use HyperEstraier Index $use_hest";
+       }
        print " increment is " . EST_CHUNK . " files:";
 
        my $results = 0;
@@ -179,7 +200,7 @@ sub hest_update {
                        my $fid = $row->{'fid'} || die "no fid?";
                        my $uri = 'file:///' . $fid;
 
-                       my $id = $hest_db->uri_to_id($uri);
+                       my $id = ($hest_db || $hest_node)->uri_to_id($uri);
                        next unless ($id == -1);
 
                        # create a document object 
@@ -203,19 +224,27 @@ sub hest_update {
                        print STDERR $doc->dump_draft,"\n" if ($debug > 1);
 
                        # register the document object to the database
-                       $hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);
+                       if ($hest_db) {
+                               $hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);
+                       } elsif ($hest_node) {
+                               $hest_node->put_doc($doc);
+                       } else {
+                               die "not supported";
+                       }
                        $added++;
                }
 
                print " $added";
-               $hest_db->sync();
+               $hest_db->sync() if ($index_path);
 
                $offset += EST_CHUNK;
 
        } while ($results == EST_CHUNK);
 
-       print ", close";
-       $hest_db->close();
+       if ($index_path) {
+               print ", close";
+               $hest_db->close();
+       }
 
        my $dur = (time() - $t) || 1;
        printf(" [%.2f/s dur: %s]\n",
index 4bfeeba..b1b871b 100644 (file)
@@ -1751,8 +1751,9 @@ $Conf{SearchUser} = 'dpavlin';
 #
 # if you want to use experimental HyperEstraier support (which require
 # installation of HyperEstraier and swig binding for perl) select
-# path to index (relative to $TopDir)
-$Conf{HyperEstraierIndex} = '/casket/';
+# path to index (relative to $TopDir) or node URI
+#$Conf{HyperEstraierIndex} = '/casket/';
+$Conf{HyperEstraierIndex} = 'http://localhost:1978/node/backuppc';
 
 #
 # temp directory for storing gzip and iso files when createing iso images