Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r677 - in branches/opensource: java/ch/psi/dms/service/server/admin sites/psi/java/ch/psi/dms/psi/service sites/psi/java/ch/psi/dms/psi/service/server sites/psi/java/ch/psi/dms/psi/service/server/admin

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r677 - in branches/opensource: java/ch/psi/dms/service/server/admin sites/psi/java/ch/psi/dms/psi/service sites/psi/java/ch/psi/dms/psi/service/server sites/psi/java/ch/psi/dms/psi/service/server/admin


Chronological Thread 
  • From: "Apache" <apache AT savannah.psi.ch>
  • To: idok-commit AT lists.psi.ch
  • Subject: [idok-commit] idok commit r677 - in branches/opensource: java/ch/psi/dms/service/server/admin sites/psi/java/ch/psi/dms/psi/service sites/psi/java/ch/psi/dms/psi/service/server sites/psi/java/ch/psi/dms/psi/service/server/admin
  • Date: Fri, 18 Jan 2008 09:47:12 +0100
  • List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
  • List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>

Author: geus AT PSI.CH
Date: Fri Jan 18 09:47:11 2008
New Revision: 677

Log:
Implemented configurability of project and repository creation

Added:

branches/opensource/java/ch/psi/dms/service/server/admin/ProjectAndRepositoryCreator.java

branches/opensource/java/ch/psi/dms/service/server/admin/SimpleProjectAndRepositoryCreator.java
branches/opensource/sites/psi/java/ch/psi/dms/psi/service/
branches/opensource/sites/psi/java/ch/psi/dms/psi/service/server/
branches/opensource/sites/psi/java/ch/psi/dms/psi/service/server/admin/

branches/opensource/sites/psi/java/ch/psi/dms/psi/service/server/admin/PSIApacheConfWriter.java
- copied, changed from r676,
/branches/opensource/sites/psi/java/ch/psi/dms/service/server/admin/PSIApacheConfWriter.java

branches/opensource/sites/psi/java/ch/psi/dms/psi/service/server/admin/PSIProjectAndRepositoryCreator.java
Modified:
branches/opensource/java/ch/psi/dms/service/server/admin/Admin.java

branches/opensource/java/ch/psi/dms/service/server/admin/TasknameParser.java

Modified: branches/opensource/java/ch/psi/dms/service/server/admin/Admin.java
==============================================================================
--- branches/opensource/java/ch/psi/dms/service/server/admin/Admin.java
(original)
+++ branches/opensource/java/ch/psi/dms/service/server/admin/Admin.java Fri
Jan 18 09:47:11 2008
@@ -5,7 +5,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -56,41 +55,26 @@

static private Pattern actionNamePattern = Pattern
.compile("(?:admin)|(?:read)|(?:write)");
+
+ static ProjectAndRepositoryCreator projectCreator;
+
+ static {
+ // Instantiate class responsible for creating projects and
repositories
+ String className = System.getProperty(
+ "ch.psi.dms.service.projectAndRepositoryCreator",
+
"ch.psi.dms.service.server.admin.SimpleProjectAndRepositoryCreator");
+ try {
+ projectCreator = (ProjectAndRepositoryCreator) Class.forName(
+ className).newInstance();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+
+ }

/**
- * Create new dms project.
- *
- * Create a new afs volume and the project directory which acts as a
mount
- * point to the afs volume.
- *
- * The name of the afs volume is dms.PROJECT where PROJECT is the project
- * name.
- *
- * The afs volumes are manipulated by running a script "dms" as user
"dmsop"
- * on host "afsadmin" using ssh. The ssh authentication is done using
- * GSSAPI. The TGT for user dmsop is obtained via a keytab file
- * /etc/krb5.keytab.dmsop. The credentials for user "dmsop" are stored
in a
- * separate credentials cache /tmp/krb5cc_dmsop.
- *
- * To delete a project manually:
- *
- * 1. obtain a TGT for dmsop AT PSI.CH using 'kinit -k -t
- * /etc/krb5.keytab.dmsop dmsop AT PSI.CH'
- *
- * 2. Remove the mount point to the AFS volume using 'fs rmm
- * /afs/psi.ch/dms/PROJECT' where PROJECT is the project name.
- *
- * 3. execute 'ssh -o "GSSAPIAuthentication yes" dmsop@afsadmin dms
remove
- * PROJECT' where PROJECT is the project name.
- *
- * To adjust a project quota manually:
- *
- * 1. obtain a TGT for dmsop AT PSI.CH using 'kinit -k -t
- * /etc/krb5.keytab.dmsop dmsop AT PSI.CH'
- *
- * 2. execute 'ssh -o "GSSAPIAuthentication yes" dmsop@afsadmin dms
setquota
- * PROJECT QUOTA' where PROJECT is the project name and QUOTA is the new
- * quota in megabytes.
+ * Create new iDok project.
*
* @param user
* Name of user on whose behalf the project is created
@@ -102,40 +86,11 @@
*/
static public void createProject(String user, String projectName, int
quota)
throws DmsException {
-
- // Test if project already exists
- if (projectExists(projectName))
- throw new DmsException(ErrorType.BAD_ARG, null,
- "Could not create new project", "Project already
exists");
-
- // Obtain TGT for dmsop AT PSI.CH
- int status;
- status = runShellCommand(new String[] { "/usr/kerberos/bin/kinit",
- "-k", "-t", "/etc/krb5.keytab.dmsop", "dmsop AT PSI.CH" },
- new String[] { "KRB5CCNAME=/tmp/krb5cc_dmsop" });
- if (status != 0) {
- throw new DmsException(ErrorType.INTERNAL, null,
- "Could not obtain credentials for dmsop AT PSI.CH",
- "kinit returned with error code " + status);
- }
-
- // Create a new AFS volume for the project and the project directory
- // mount
- logger_.info("Creating AFS volume and mount point for project "
- + projectName);
- status = runShellCommand(new String[] { "/usr/bin/ssh", "-o",
- "GSSAPIAuthentication yes", "dmsop@afsadmin", "dms",
"create",
- projectName, String.format("%d", quota * 1024) },
- new String[] { "KRB5CCNAME=/tmp/krb5cc_dmsop" });
- if (status != 0) {
- throw new DmsException(ErrorType.INTERNAL, null,
- "Could not create AFS volume for project " + projectName,
- "ssh returned with error code " + status);
- }
+ projectCreator.createProject(projectName, quota);
}

/**
- * Create new dms repository.
+ * Create new iDok repository.
*
* @param user
* Name of user on whose behalf the repository is created
@@ -147,99 +102,7 @@
*/
static public void createRepository(String user, String projectName,
String repositoryName) throws DmsException {
- File repositoryDir = getRepositoryDir(projectName, repositoryName);
- File schemaDir = getSchemaDir(projectName, repositoryName);
- InputStream schemaFileFrom = Admin.class
- .getResourceAsStream("schema/DublinCore.schema");
- InputStream postCommitFileFrom = Admin.class
- .getResourceAsStream("hooks/post-commit");
- InputStream mailerConfFileFrom = Admin.class
- .getResourceAsStream("conf/mailer.conf");
- File schemaFileTo = getSchemaFile(projectName, repositoryName,
- "DublinCore");
- File postCommitFileTo = new File(getSvnHooksDir(projectName,
- repositoryName), "post-commit");
- File mailerConfFileTo = new File(getSvnConfDir(projectName,
- repositoryName), "mailer.conf");
- File apacheConfFile = getApacheConfFile(projectName, repositoryName);
-
- // Test if project exists
- if (!projectExists(projectName))
- throw new DmsException(ErrorType.BAD_ARG, null,
- "Could not create new repository", "Project does not
exist");
-
- // Test if repository already exists
- if (repositoryExists(projectName, repositoryName))
- throw new DmsException(ErrorType.BAD_ARG, null,
- "Could not create new repository",
- "Repository already exists");
-
- // Create repository
- logger_.info("Creating new repository in directory "
- + repositoryDir.getAbsolutePath());
- String[] cmd = { "svnadmin", "create", "--fs-type", "fsfs",
- repositoryDir.getAbsolutePath() };
- int status = runShellCommand(cmd, null);
- if (status != 0) {
- throw new DmsException(ErrorType.INTERNAL, null,
- "Could not create new repository",
- "Error when executing svnadmin create command");
- }
-
- // After this point we need to clean up in case of a failure
- try {
- // Create default Metadata schema file
- logger_.info("Creating new directory "
- + schemaDir.getAbsolutePath());
- boolean done = schemaDir.mkdir();
- if (!done)
- throw new DmsException(ErrorType.INTERNAL, null,
- "Could not create new repository",
- "Could not create schema dir");
-
- logger_.info("Copying schema file to "
- + schemaFileTo.getAbsolutePath());
- copyStreamToFile(schemaFileFrom, schemaFileTo);
-
- // hooks/post-commit
- logger_.info("Copying to " + postCommitFileTo.getAbsolutePath());
- copyStreamToFile(postCommitFileFrom, postCommitFileTo);
- // postCommitFileTo.setExecutable(true);
- status = runShellCommand(new String[] { "chmod", "a+x",
- postCommitFileTo.getAbsolutePath() }, null);
- if (status != 0) {
- throw new DmsException(ErrorType.INTERNAL, null,
- "Could not set executable bit on "
- + postCommitFileTo.getAbsolutePath(), "");
- }
-
- // conf/mailer.conf
- logger_.info("Copying to " + mailerConfFileTo.getAbsolutePath());
- copyStreamToFile(mailerConfFileFrom, mailerConfFileTo);
-
- // FIXME: The URI should not be hardcoded to dms.psi.ch
- logger_.info("Success: new repository URI is "
- + new URI("https", "dms.psi.ch", "/" + projectName + "/"
- + repositoryName, null));
- } catch (Exception e) {
- // Cleanup: Remove repository dir and apache conf file
- boolean done = apacheConfFile.delete();
- if (!done)
- logger_.fine("Deleting " + apacheConfFile.getAbsolutePath()
- + " failed");
-
- String[] cmd2 = { "rm", "-rf", repositoryDir.getAbsolutePath() };
- done = runShellCommand(cmd2, null) == 0;
- if (!done)
- logger_.fine("Deleting " + repositoryDir.getAbsolutePath()
- + " failed");
-
- if (e instanceof DmsException)
- throw (DmsException) e;
- else
- throw new DmsException(ErrorType.INTERNAL, null,
- "Could not create new repository", e.getMessage(),
e);
- }
+ projectCreator.createRepository(projectName, repositoryName);
}

/**
@@ -252,7 +115,7 @@
* @return Abstract pathname of the generated temporary file.
* @throws IOException
*/
- static private void copyStreamToFile(InputStream is, File out)
+ public static void copyStreamToFile(InputStream is, File out)
throws IOException {
FileOutputStream os = new FileOutputStream(out);
byte[] buf = new byte[4096];
@@ -531,7 +394,7 @@
* @return Exit status returned by the shell command or -1 if an
exception
* occurred.
*/
- static int runShellCommand(String[] cmd, String[] envp) {
+ public static int runShellCommand(String[] cmd, String[] envp) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < cmd.length; ++i)
buf.append(cmd[i] + " ");
@@ -550,12 +413,12 @@
}

/** Return dms project directory */
- static private File getProjectDir(String projectName) {
+ static File getProjectDir(String projectName) {
return new File(projectRoot, projectName);
}

/** Return directory containing repository */
- static File getRepositoryDir(String projectName, String repositoryName) {
+ public static File getRepositoryDir(String projectName, String
repositoryName) {
return new File(getProjectDir(projectName), repositoryName);
}

@@ -566,22 +429,22 @@
}

/** Return "conf" directory of subversion repository */
- static private File getSvnConfDir(String projectName, String
repositoryName) {
+ public static File getSvnConfDir(String projectName, String
repositoryName) {
return new File(getRepositoryDir(projectName, repositoryName),
"conf");
}

/** Return "hooks" directory of subversion repository */
- static private File getSvnHooksDir(String projectName, String
repositoryName) {
+ public static File getSvnHooksDir(String projectName, String
repositoryName) {
return new File(getRepositoryDir(projectName, repositoryName),
"hooks");
}

/** Return directory containing dms metadata schema */
- static private File getSchemaDir(String projectName, String
repositoryName) {
+ public static File getSchemaDir(String projectName, String
repositoryName) {
return new File(getSvnConfDir(projectName, repositoryName),
"schema");
}

/** Return apache configuration file related to repository */
- static File getApacheConfFile(String projectName, String repositoryName)
{
+ public static File getApacheConfFile(String projectName, String
repositoryName) {
return new File(httpdConfDir, projectName + "@" + repositoryName
+ ".conf");
}

Added:
branches/opensource/java/ch/psi/dms/service/server/admin/ProjectAndRepositoryCreator.java
==============================================================================
--- (empty file)
+++
branches/opensource/java/ch/psi/dms/service/server/admin/ProjectAndRepositoryCreator.java
Fri Jan 18 09:47:11 2008
@@ -0,0 +1,34 @@
+package ch.psi.dms.service.server.admin;
+
+import ch.psi.dms.common.errorhandling.DmsException;
+
+public interface ProjectAndRepositoryCreator {
+ /**
+ * Create new iDok project.
+ *
+ * Usually this method creates a directory under which all repositories
+ * belonging to the project will be located and reserves space (quota)
for
+ * these repositories.
+ *
+ * In implementations that do not support a quota mechanism, the
+ * <code>quota</code> parameter is ignored.
+ *
+ * @param projectName
+ * Project name
+ * @param quota
+ * Quota for the iDok project in megabytes
+ * @throws DmsException
+ */
+ void createProject(String projectName, int quota) throws DmsException;
+
+ /**
+ * Creates an iDok repository.
+ *
+ * @param projectName
+ * Name of project to which the new repository will belong
+ * @param repositoryName
+ * Repository name
+ * @throws DmsException
+ */
+ void createRepository(String projectName, String repositoryName) throws
DmsException;
+}

Added:
branches/opensource/java/ch/psi/dms/service/server/admin/SimpleProjectAndRepositoryCreator.java
==============================================================================
--- (empty file)
+++
branches/opensource/java/ch/psi/dms/service/server/admin/SimpleProjectAndRepositoryCreator.java
Fri Jan 18 09:47:11 2008
@@ -0,0 +1,114 @@
+package ch.psi.dms.service.server.admin;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.logging.Logger;
+
+import ch.psi.dms.common.config.Setup;
+import ch.psi.dms.common.errorhandling.DmsException;
+import ch.psi.dms.common.errorhandling.ErrorType;
+
+/**
+ * Basic implementation of the ProjectAndRepositoryCreator interface.
+ */
+public class SimpleProjectAndRepositoryCreator implements
+ ProjectAndRepositoryCreator {
+
+ static private Logger logger_ =
Setup.getInstance().getLogger("service.admin");
+
+ /**
+ * @see
ch.psi.dms.service.server.admin.ProjectAndRepositoryCreator#createProject(java.lang.String,
+ * int)
+ */
+ public void createProject(String projectName, int quota)
+ throws DmsException {
+
+ // Test if project already exists
+ if (Admin.projectExists(projectName))
+ throw new DmsException(ErrorType.BAD_ARG, null,
+ "Could not create new project", "Project already
exists");
+
+ // Create project directory
+ File projectDir = Admin.getProjectDir(projectName);
+ boolean done = projectDir.mkdir();
+ if (!done)
+ throw new DmsException(ErrorType.BAD_ARG, null,
+ "Could not create new project",
+ "Unable to create directory " + projectDir);
+ }
+
+ /**
+ * @see
ch.psi.dms.service.server.admin.ProjectAndRepositoryCreator#createRepository(java.lang.String,
+ * java.lang.String)
+ */
+ public void createRepository(String projectName, String repositoryName)
+ throws DmsException {
+ File repositoryDir = Admin.getRepositoryDir(projectName,
repositoryName);
+ File schemaDir = Admin.getSchemaDir(projectName, repositoryName);
+ InputStream schemaFileFrom = Admin.class
+ .getResourceAsStream("schema/DublinCore.schema");
+ File schemaFileTo = Admin.getSchemaFile(projectName, repositoryName,
+ "DublinCore");
+ File apacheConfFile = Admin.getApacheConfFile(projectName,
repositoryName);
+
+ // Test if project exists
+ if (!Admin.projectExists(projectName))
+ throw new DmsException(ErrorType.BAD_ARG, null,
+ "Could not create new repository", "Project does not
exist");
+
+ // Test if repository already exists
+ if (Admin.repositoryExists(projectName, repositoryName))
+ throw new DmsException(ErrorType.BAD_ARG, null,
+ "Could not create new repository",
+ "Repository already exists");
+
+ // Create repository
+ logger_.info("Creating new repository in directory "
+ + repositoryDir.getAbsolutePath());
+ String[] cmd = { "svnadmin", "create", "--fs-type", "fsfs",
+ repositoryDir.getAbsolutePath() };
+ int status = Admin.runShellCommand(cmd, null);
+ if (status != 0) {
+ throw new DmsException(ErrorType.INTERNAL, null,
+ "Could not create new repository",
+ "Error when executing \"svnadmin create\" command");
+ }
+
+ // After this point we need to clean up in case of a failure
+ try {
+ // Create default meta data schema file
+ logger_.info("Creating new directory "
+ + schemaDir.getAbsolutePath());
+ boolean done = schemaDir.mkdir();
+ if (!done)
+ throw new DmsException(ErrorType.INTERNAL, null,
+ "Could not create new repository",
+ "Could not create schema dir");
+
+ logger_.info("Copying schema file to "
+ + schemaFileTo.getAbsolutePath());
+ Admin.copyStreamToFile(schemaFileFrom, schemaFileTo);
+
+ logger_.info("Success: new repository created");
+ } catch (Exception e) {
+ // Cleanup: Remove repository directory and apache conf file
+ boolean done = apacheConfFile.delete();
+ if (!done)
+ logger_.fine("Deleting " + apacheConfFile.getAbsolutePath()
+ + " failed");
+
+ String[] cmd2 = { "rm", "-rf", repositoryDir.getAbsolutePath() };
+ done = Admin.runShellCommand(cmd2, null) == 0;
+ if (!done)
+ logger_.fine("Deleting " + repositoryDir.getAbsolutePath()
+ + " failed");
+
+ if (e instanceof DmsException)
+ throw (DmsException) e;
+ else
+ throw new DmsException(ErrorType.INTERNAL, null,
+ "Could not create new repository", e.getMessage(),
e);
+ }
+ }
+
+}

Modified:
branches/opensource/java/ch/psi/dms/service/server/admin/TasknameParser.java
==============================================================================
---
branches/opensource/java/ch/psi/dms/service/server/admin/TasknameParser.java
(original)
+++
branches/opensource/java/ch/psi/dms/service/server/admin/TasknameParser.java
Fri Jan 18 09:47:11 2008
@@ -48,7 +48,7 @@
* @return the path component of the task or "/" if there is no path
* component.
*/
- static String getPath(String task) {
+ public static String getPath(String task) {
if (task.equals("<admin>"))
return "/";
else {

Copied:
branches/opensource/sites/psi/java/ch/psi/dms/psi/service/server/admin/PSIApacheConfWriter.java
(from r676,
/branches/opensource/sites/psi/java/ch/psi/dms/service/server/admin/PSIApacheConfWriter.java)
==============================================================================
---
/branches/opensource/sites/psi/java/ch/psi/dms/service/server/admin/PSIApacheConfWriter.java
(original)
+++
branches/opensource/sites/psi/java/ch/psi/dms/psi/service/server/admin/PSIApacheConfWriter.java
Fri Jan 18 09:47:11 2008
@@ -1,4 +1,4 @@
-package ch.psi.dms.service.server.admin;
+package ch.psi.dms.psi.service.server.admin;

import java.io.PrintWriter;
import java.io.Writer;
@@ -9,6 +9,9 @@

import ch.psi.dms.common.errorhandling.DmsException;
import ch.psi.dms.common.util.DmsPermission;
+import ch.psi.dms.service.server.admin.Admin;
+import ch.psi.dms.service.server.admin.ApacheConfWriter;
+import ch.psi.dms.service.server.admin.TasknameParser;

/**
* PSI specific ApacheConfWriter
@@ -93,9 +96,9 @@
for (String action : rootPermissions.keySet()) {
String tail = null;
if (action.equals("admin") || action.equals("write"))
- tail = "=rw\n";
+ tail = "=rw";
else if (action.equals("read"))
- tail = "=r\n";
+ tail = "=r";
for (String username : rootPermissions.get(action)) {
pw.print(username);
pw.println(tail);

Added:
branches/opensource/sites/psi/java/ch/psi/dms/psi/service/server/admin/PSIProjectAndRepositoryCreator.java
==============================================================================
--- (empty file)
+++
branches/opensource/sites/psi/java/ch/psi/dms/psi/service/server/admin/PSIProjectAndRepositoryCreator.java
Fri Jan 18 09:47:11 2008
@@ -0,0 +1,193 @@
+package ch.psi.dms.psi.service.server.admin;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.logging.Logger;
+
+import ch.psi.dms.common.config.Setup;
+import ch.psi.dms.common.errorhandling.DmsException;
+import ch.psi.dms.common.errorhandling.ErrorType;
+import ch.psi.dms.service.server.admin.Admin;
+import ch.psi.dms.service.server.admin.ProjectAndRepositoryCreator;
+
+/**
+ * PSI specific implementation of the ProjectAndRepositoryCreator interface.
+ */
+public class PSIProjectAndRepositoryCreator implements
+ ProjectAndRepositoryCreator {
+
+ static private Logger logger_ =
Setup.getInstance().getLogger("service.admin");
+
+ /**
+ * Create a new afs volume and the project directory which acts as a
mount
+ * point to the afs volume.
+ *
+ * The name of the afs volume is dms.PROJECT where PROJECT is the project
+ * name.
+ *
+ * The afs volumes are manipulated by running a script "dms" as user
"dmsop"
+ * on host "afsadmin" using ssh. The ssh authentication is done using
+ * GSSAPI. The TGT for user dmsop is obtained via a keytab file
+ * /etc/krb5.keytab.dmsop. The credentials for user "dmsop" are stored
in a
+ * separate credentials cache /tmp/krb5cc_dmsop.
+ *
+ * To delete a project manually:
+ *
+ * 1. obtain a TGT for dmsop AT PSI.CH using 'kinit -k -t
+ * /etc/krb5.keytab.dmsop dmsop AT PSI.CH'
+ *
+ * 2. Remove the mount point to the AFS volume using 'fs rmm
+ * /afs/psi.ch/dms/PROJECT' where PROJECT is the project name.
+ *
+ * 3. execute 'ssh -o "GSSAPIAuthentication yes" dmsop@afsadmin dms
remove
+ * PROJECT' where PROJECT is the project name.
+ *
+ * To adjust a project quota manually:
+ *
+ * 1. obtain a TGT for dmsop AT PSI.CH using 'kinit -k -t
+ * /etc/krb5.keytab.dmsop dmsop AT PSI.CH'
+ *
+ * 2. execute 'ssh -o "GSSAPIAuthentication yes" dmsop@afsadmin dms
setquota
+ * PROJECT QUOTA' where PROJECT is the project name and QUOTA is the new
+ * quota in megabytes.
+ *
+ * @see
ch.psi.dms.service.server.admin.ProjectAndRepositoryCreator#createProject(java.lang.String,
+ * int)
+ */
+ public void createProject(String projectName, int quota)
+ throws DmsException {
+
+ // Test if project already exists
+ if (Admin.projectExists(projectName))
+ throw new DmsException(ErrorType.BAD_ARG, null,
+ "Could not create new project", "Project already
exists");
+
+ // Obtain TGT for dmsop AT PSI.CH
+ int status;
+ status = Admin.runShellCommand(new String[] {
"/usr/kerberos/bin/kinit",
+ "-k", "-t", "/etc/krb5.keytab.dmsop", "dmsop AT PSI.CH" },
+ new String[] { "KRB5CCNAME=/tmp/krb5cc_dmsop" });
+ if (status != 0) {
+ throw new DmsException(ErrorType.INTERNAL, null,
+ "Could not obtain credentials for dmsop AT PSI.CH",
+ "kinit returned with error code " + status);
+ }
+
+ // Create a new AFS volume for the project and the project directory
+ // mount
+ logger_.info("Creating AFS volume and mount point for project "
+ + projectName);
+ status = Admin.runShellCommand(new String[] { "/usr/bin/ssh", "-o",
+ "GSSAPIAuthentication yes", "dmsop@afsadmin", "dms",
"create",
+ projectName, String.format("%d", quota * 1024) },
+ new String[] { "KRB5CCNAME=/tmp/krb5cc_dmsop" });
+ if (status != 0) {
+ throw new DmsException(ErrorType.INTERNAL, null,
+ "Could not create AFS volume for project " + projectName,
+ "ssh returned with error code " + status);
+ }
+ }
+
+ /**
+ * @see
ch.psi.dms.service.server.admin.ProjectAndRepositoryCreator#createRepository(java.lang.String,
+ * java.lang.String)
+ */
+ public void createRepository(String projectName, String repositoryName)
+ throws DmsException {
+ File repositoryDir = Admin.getRepositoryDir(projectName,
repositoryName);
+ File schemaDir = Admin.getSchemaDir(projectName, repositoryName);
+ InputStream schemaFileFrom = Admin.class
+ .getResourceAsStream("schema/DublinCore.schema");
+ InputStream postCommitFileFrom = Admin.class
+ .getResourceAsStream("hooks/post-commit");
+ InputStream mailerConfFileFrom = Admin.class
+ .getResourceAsStream("conf/mailer.conf");
+ File schemaFileTo = Admin.getSchemaFile(projectName, repositoryName,
+ "DublinCore");
+ File postCommitFileTo = new File(Admin.getSvnHooksDir(projectName,
+ repositoryName), "post-commit");
+ File mailerConfFileTo = new File(Admin.getSvnConfDir(projectName,
+ repositoryName), "mailer.conf");
+ File apacheConfFile = Admin.getApacheConfFile(projectName,
repositoryName);
+
+ // Test if project exists
+ if (!Admin.projectExists(projectName))
+ throw new DmsException(ErrorType.BAD_ARG, null,
+ "Could not create new repository", "Project does not
exist");
+
+ // Test if repository already exists
+ if (Admin.repositoryExists(projectName, repositoryName))
+ throw new DmsException(ErrorType.BAD_ARG, null,
+ "Could not create new repository",
+ "Repository already exists");
+
+ // Create repository
+ logger_.info("Creating new repository in directory "
+ + repositoryDir.getAbsolutePath());
+ String[] cmd = { "svnadmin", "create", "--fs-type", "fsfs",
+ repositoryDir.getAbsolutePath() };
+ int status = Admin.runShellCommand(cmd, null);
+ if (status != 0) {
+ throw new DmsException(ErrorType.INTERNAL, null,
+ "Could not create new repository",
+ "Error when executing \"svnadmin create\" command");
+ }
+
+ // After this point we need to clean up in case of a failure
+ try {
+ // Create default meta data schema file
+ logger_.info("Creating new directory "
+ + schemaDir.getAbsolutePath());
+ boolean done = schemaDir.mkdir();
+ if (!done)
+ throw new DmsException(ErrorType.INTERNAL, null,
+ "Could not create new repository",
+ "Could not create schema dir");
+
+ logger_.info("Copying schema file to "
+ + schemaFileTo.getAbsolutePath());
+ Admin.copyStreamToFile(schemaFileFrom, schemaFileTo);
+
+ // hooks/post-commit
+ logger_.info("Copying to " + postCommitFileTo.getAbsolutePath());
+ Admin.copyStreamToFile(postCommitFileFrom, postCommitFileTo);
+ // postCommitFileTo.setExecutable(true);
+ status = Admin.runShellCommand(new String[] { "chmod", "a+x",
+ postCommitFileTo.getAbsolutePath() }, null);
+ if (status != 0) {
+ throw new DmsException(ErrorType.INTERNAL, null,
+ "Could not set executable bit on "
+ + postCommitFileTo.getAbsolutePath(), "");
+ }
+
+ // conf/mailer.conf
+ logger_.info("Copying to " + mailerConfFileTo.getAbsolutePath());
+ Admin.copyStreamToFile(mailerConfFileFrom, mailerConfFileTo);
+
+ // FIXME: The URI should not be hardcoded to dms.psi.ch
+ logger_.info("Success: new repository URI is "
+ + new URI("https", "dms.psi.ch", "/" + projectName + "/"
+ + repositoryName, null));
+ } catch (Exception e) {
+ // Cleanup: Remove repository dir and apache conf file
+ boolean done = apacheConfFile.delete();
+ if (!done)
+ logger_.fine("Deleting " + apacheConfFile.getAbsolutePath()
+ + " failed");
+
+ String[] cmd2 = { "rm", "-rf", repositoryDir.getAbsolutePath() };
+ done = Admin.runShellCommand(cmd2, null) == 0;
+ if (!done)
+ logger_.fine("Deleting " + repositoryDir.getAbsolutePath()
+ + " failed");
+
+ if (e instanceof DmsException)
+ throw (DmsException) e;
+ else
+ throw new DmsException(ErrorType.INTERNAL, null,
+ "Could not create new repository", e.getMessage(),
e);
+ }
+ }
+
+}



  • [idok-commit] idok commit r677 - in branches/opensource: java/ch/psi/dms/service/server/admin sites/psi/java/ch/psi/dms/psi/service sites/psi/java/ch/psi/dms/psi/service/server sites/psi/java/ch/psi/dms/psi/service/server/admin, Apache, 01/18/2008

Archive powered by MHonArc 2.6.19.

Top of Page