]> andersk Git - moira.git/commitdiff
New strategy: use Pro*C so it's less absymally slow.
authorzacheiss <zacheiss>
Thu, 15 Nov 2007 22:09:20 +0000 (22:09 +0000)
committerzacheiss <zacheiss>
Thu, 15 Nov 2007 22:09:20 +0000 (22:09 +0000)
gen/Makefile.in
gen/confluence.gen [deleted file]
gen/confluence.pc [new file with mode: 0644]

index 395ac93c50a9ec42cfa424d8b6fe365a34ca9da6..8828a553b661c1a4d936c381c4e1559faa2a9763 100644 (file)
@@ -30,20 +30,20 @@ LIB_OBJS=util.o tar.o genacl.o
 LIB_CFILES=genacl.c
 LIB_TARGET=libdcm.a
 
-OBJS=  acl.o boot.o dhcp.o directory.o events.o hesiod.o hosts.o mailhub.o \
-       ndb.o network.o nfs.o pobox.o postoffice.o print.o \
+OBJS=  acl.o boot.o confluence.o dhcp.o directory.o events.o hesiod.o \
+       hosts.o mailhub.o ndb.o network.o nfs.o pobox.o postoffice.o print.o \
        winad.o www.o zephyr.o
 
-CFILES= acl.c boot.c dhcp.c directory.c events.c hesiod.c hosts.c mailhub.c \
-       ndb.c network.c nfs.c pobox.c postoffice.c print.c \
+CFILES= acl.c boot.c confluence.c dhcp.c directory.c events.c hesiod.c \
+       hosts.c mailhub.c ndb.c network.c nfs.c pobox.c postoffice.c print.c \
        winad.c www.c zephyr.c
 
-TARGET=        acl.gen boot.gen dhcp.gen directory.gen events.gen hesiod.gen hosts.gen \
-       mailhub.gen ndb.gen network.gen nfs.gen pobox.gen \
-       postoffice.gen print.gen winad.gen www.gen zephyr.gen
+TARGET=        acl.gen boot.gen confluence.gen dhcp.gen directory.gen events.gen \
+       hesiod.gen hosts.gen mailhub.gen ndb.gen network.gen nfs.gen \
+       pobox.gen postoffice.gen print.gen winad.gen www.gen zephyr.gen
 
 SCRIPTS=access.gen access.sh acl.sh aliases.sh boot.sh ca.gen calendar.gen \
-       confluence.gen dhcp.sh events.sh hesiod.sh ip-billing.gen \
+       dhcp.sh events.sh hesiod.sh ip-billing.gen \
        ip-billing.sh ldap.gen longjobs.gen longjobs.sh mailhosts.gen \
        mailhub.sh mailman.gen mailman.sh nagios-colo.gen nagios-colo.sh \
        nagios-printers.gen nagios-printers.sh ndb.sh nfs.sh null.sh \
@@ -95,6 +95,9 @@ directory.gen: directory.o libdcm.a $(MR_LIBDEP)
 events.gen: events.o libdcm.a $(MR_LIBDEP)
        $(CC) -o $@ $(LDFLAGS) events.o libdcm.a $(SQL_LIBS) $(LIBS)
 
+confluence.gen: confluence.o libdcm.a $(MR_LIBDEP)
+       $(CC) -o $@ $(LDFLAGS) confluence.o libdcm.a $(SQL_LIBS) $(LIBS)
+
 ndb.gen: ndb.o libdcm.a $(MR_LIBDEP)
        $(CC) -o $@ $(LDFLAGS) ndb.o libdcm.a $(SQL_LIBS) $(LIBS)
 
diff --git a/gen/confluence.gen b/gen/confluence.gen
deleted file mode 100755 (executable)
index 83eac30..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/moira/bin/perl -Tw
-
-# $Id$
-
-# The following exit codes are defined and MUST BE CONSISTENT with the
-# error codes the library uses:
-$MR_DBMS_ERR = 47836421;
-
-$ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin";
-
-$outfile = '/moira/dcm/confluence.out';
-umask 022;
-
-use DBI;
-
-$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
-  || exit $MR_DBMS_ERR;
-
-open(OUT, ">$outfile");
-
-$sth = $dbh->prepare("SELECT l.name, l.gid FROM list l " .
-                    "WHERE l.active = 1 AND l.grouplist = 1 ORDER by l.name")
-    || exit $MR_DBMS_ERR;
-
-$sth->execute;
-    
-while (($name, $gid) = $sth->fetchrow_array) {
-    $sth2 = $dbh->prepare("SELECT UNIQUE i.member_type, i.member_id " .
-                         "FROM imembers i, list l " .
-                         "WHERE l.name = " . $dbh->quote($name) .
-                         "AND i.list_id = l.list_id " .
-                         "AND (i.member_type = 'USER' " .
-                         "OR i.member_type = 'STRING')") || 
-                         exit $MR_DBMS_ERR;
-    $sth2->execute;
-    
-    $row = "$name:$gid:";
-    $row =~ s/\0//g;
-    print OUT $row;
-    $maybecomma = "";
-    
-    while (($type, $id) = $sth2->fetchrow_array) {
-       if ($type eq "USER") {
-           ($member) = $dbh->selectrow_array("SELECT login FROM users " .
-                                             "WHERE users_id = " . 
-                                             $dbh->quote($id)) ||
-                                             exit $MR_DBMS_ERR;
-           $member = $member . "\@mit.edu";
-       }
-       elsif ($type eq "STRING") {
-           ($member) = $dbh->selectrow_array("SELECT string " .
-                                             "FROM strings " .
-                                             "WHERE string_id = " .
-                                             $dbh->quote($id)) ||
-                                             exit $MR_DBMS_ERR;
-       }
-       $row = "$maybecomma$member";
-       $row =~ s/\0//g;
-       print OUT $row;
-       $maybecomma = ",";
-    }
-    
-    $row = "\n";
-    $row =~ s/\0//g;
-    print OUT $row;
-}
-
-close(OUT);
-$dbh->disconnect;
-
-exit 0;
diff --git a/gen/confluence.pc b/gen/confluence.pc
new file mode 100644 (file)
index 0000000..5469979
--- /dev/null
@@ -0,0 +1,137 @@
+/* $Id$
+ *
+ * (c) Copyright 2007 by the Massachusetts Institute of Technology.
+ */
+
+#include <mit-copyright.h>
+#include <moira.h>
+#include <moira_site.h>
+
+#include <sys/stat.h>
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "util.h"
+
+EXEC SQL INCLUDE sqlca;
+
+char *whoami = "confluence.gen";
+char *db = "moira/moira";
+
+struct hash *lists;
+
+void output_list(int id, void *list, void *out);
+
+int main(int argc, char **argv)
+{
+  char filename[MAXPATHLEN], *targetfile, *l;
+  FILE *out = stdout;
+  int cnt = 0;
+  EXEC SQL BEGIN DECLARE SECTION;
+  int lid;
+  char lname[LIST_NAME_SIZE];
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL CONNECT :db;
+
+  if (argc == 2)
+    {
+      targetfile = argv[1];
+      sprintf(filename, "%s~", targetfile);
+      if (!(out = fopen(filename, "w")))
+       {
+         fprintf(stderr, "unable to open %s for output\n", filename);
+         exit(MR_OCONFIG);
+       }
+    }
+  else if (argc != 1)
+    {
+      fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
+      exit(MR_ARGS);
+    }
+
+  lists = create_hash(15000);
+
+  EXEC SQL DECLARE l_cursor CURSOR FOR
+    SELECT l.list_id, l.name FROM list l
+    WHERE l.active = 1 and l.grouplist = 1;
+  EXEC SQL OPEN l_cursor;
+  while (1)
+    {
+      EXEC SQL FETCH l_cursor INTO :lid, :lname;
+      if (sqlca.sqlcode)
+       break;
+      l = strdup(strtrim(lname));
+      if (hash_store(lists, lid, l) < 0)
+       {
+         fprintf(stderr, "Out of memory!\n");
+         exit(MR_NO_MEM);
+       }
+      cnt++;
+    }
+  EXEC SQL CLOSE l_cursor;
+  fprintf(stderr, "Loaded %d lists\n", cnt);
+
+  hash_step(lists, output_list, out);
+
+  if (fclose(out))
+    {
+      perror("close failed");
+      exit(MR_CCONFIG);
+    }
+  
+  if (argc == 2)
+    fix_file(targetfile);
+  exit(MR_SUCCESS);
+}
+
+void output_list(int id, void *list, void *out)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  char *l = list;
+  int lid = id;
+  int lgid;
+  char login[USERS_LOGIN_SIZE];
+  char stringmember[STRINGS_STRING_SIZE];
+  EXEC SQL END DECLARE SECTION;
+  char *maybecomma = "";
+
+  EXEC SQL SELECT gid INTO :lgid FROM list WHERE list_id = :lid;
+
+  fprintf(out, "%s:%d:", list, lgid);
+
+  EXEC SQL DECLARE u_cursor CURSOR FOR
+    SELECT UNIQUE u.login FROM users u, imembers i, list l
+    WHERE l.list_id = :lid AND l.list_id = i.list_id AND
+    i.member_type = 'USER' AND i.member_id = u.users_id;
+  EXEC SQL OPEN u_cursor;
+  while (1)
+    {
+      EXEC SQL FETCH u_cursor INTO :login;
+      if (sqlca.sqlcode)
+       break;
+      fprintf(out, "%s%s%s", maybecomma, strtrim(login), "@mit.edu");
+      maybecomma = ",";
+    }
+  EXEC SQL CLOSE u_cursor;
+
+  EXEC SQL DECLARE s_cursor CURSOR FOR
+    SELECT UNIQUE s.string FROM strings s, imembers i, list l
+    WHERE l.list_id = :lid AND l.list_id = i.list_id AND
+    i.member_type = 'STRING' AND i.member_id = s.string_id;
+  EXEC SQL OPEN s_cursor;
+  while (1)
+    {
+      EXEC SQL FETCH s_cursor INTO :stringmember;
+      if (sqlca.sqlcode)
+       break;
+      fprintf(out, "%s%s", maybecomma, strtrim(stringmember));
+      maybecomma = ",";
+    }
+  EXEC SQL CLOSE s_cursor;
+
+  fprintf(out, "\n");
+}
This page took 0.065757 seconds and 5 git commands to generate.