7 commits - schema/spacewalk web/modules
by Jan Pazdziora
schema/spacewalk/postgres/packages/rhn_channel.pkb | 2 +-
web/modules/rhn/RHN/DB.pm | 10 ++++------
web/modules/rhn/RHN/DB/Channel.pm | 2 +-
web/modules/rhn/RHN/DB/ChannelEditor.pm | 4 ++--
web/modules/rhn/RHN/DB/TableClass.pm | 7 +++++--
5 files changed, 13 insertions(+), 12 deletions(-)
New commits:
commit 4684cefca6af77089c5ad6d6d63e63144a570917
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 13:34:13 2010 +0200
Use current_timestamp instead of the Oracle-specific sysdate in set_cloned_from.
diff --git a/web/modules/rhn/RHN/DB/Channel.pm b/web/modules/rhn/RHN/DB/Channel.pm
index d1c0c01..b0f160d 100644
--- a/web/modules/rhn/RHN/DB/Channel.pm
+++ b/web/modules/rhn/RHN/DB/Channel.pm
@@ -919,7 +919,7 @@ EOQ
INSERT
INTO rhnChannelCloned
(original_id, id, created, modified)
-VALUES (:from_cid, :to_cid, sysdate, sysdate)
+VALUES (:from_cid, :to_cid, current_timestamp, current_timestamp)
EOQ
$sth = $dbh->prepare($query);
commit 367578ac437fb700013eb841bd23e8494ff5f158
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 13:30:45 2010 +0200
Avoid the integer arithmetics with timestamps in PostgreSQL.
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index 63630aa..40902eb 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -999,7 +999,7 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
last_modified_value := date_to_use;
if last_modified_value <= channel_last_modified then
- last_modified_value := last_modified_value + 1/86400;
+ last_modified_value := last_modified_value + interval '1 second';
end if;
update rhnChannel set last_modified = last_modified_value
commit 396629dbc9ff2b28ada4e30b30835bc67b1beffb
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 13:21:46 2010 +0200
To PostgreSQL, procedures are just functions, call them as such.
diff --git a/web/modules/rhn/RHN/DB.pm b/web/modules/rhn/RHN/DB.pm
index 00025d6..5f6a266 100644
--- a/web/modules/rhn/RHN/DB.pm
+++ b/web/modules/rhn/RHN/DB.pm
@@ -420,6 +420,9 @@ sub ping {
# some extension functions
sub call_procedure {
my $self = shift;
+ if ($self->{Driver}->{Name} eq 'Pg') {
+ return $self->call_function(@_);
+ }
my $procname = shift;
my @params = @_;
my @placeholders = map { ":p$_" } 1 .. scalar @params;
commit a09360c65770933faecd310b92aeb77a5cfd3b67
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 13:17:54 2010 +0200
We do not seem to be using the inout parameter anywhere in our code, remove the code to make porting to PostgreSQL easier.
diff --git a/web/modules/rhn/RHN/DB.pm b/web/modules/rhn/RHN/DB.pm
index d0b076c..00025d6 100644
--- a/web/modules/rhn/RHN/DB.pm
+++ b/web/modules/rhn/RHN/DB.pm
@@ -433,12 +433,7 @@ sub call_procedure {
my $i = 0;
foreach my $param (@params) {
- if (ref $param eq 'SCALAR') {
- $sth->bind_param_inout($placeholders[$i], $param, 4096);
- }
- else {
- $sth->bind_param($placeholders[$i], $param);
- }
+ $sth->bind_param($placeholders[$i], $param);
$i++;
}
commit 6e533cf16b59b5a72abe8762d1faff244743e8b5
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 13:11:24 2010 +0200
Use current_timestamp instead of the Oracle-specific sysdate in clone_channel_packages.
Addressing
DBD::Pg::st execute failed: ERROR: column "sysdate" does not exist at character 211
diff --git a/web/modules/rhn/RHN/DB/ChannelEditor.pm b/web/modules/rhn/RHN/DB/ChannelEditor.pm
index 8549757..f89e71c 100644
--- a/web/modules/rhn/RHN/DB/ChannelEditor.pm
+++ b/web/modules/rhn/RHN/DB/ChannelEditor.pm
@@ -294,7 +294,7 @@ INSERT
INTO rhnRepoRegenQueue
(id, channel_label, client, reason, force, bypass_filters, next_action, created, modified)
VALUES (null,
- :label, 'perl-web::clone_channel_packages', NULL, 'N', 'N', sysdate, sysdate, sysdate)
+ :label, 'perl-web::clone_channel_packages', NULL, 'N', 'N', current_timestamp, current_timestamp, current_timestamp)
EOQ
my $channel = RHN::Channel->lookup(-id => $to_cid);
commit 51b500794f93a2a584a200487feb1d13b0abf211
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 13:09:53 2010 +0200
Since we have trigger which sets rhnRepoRegenQueue.id since f2153167da508852183501f320c2e71c08a0441c, we can avoid .nextval.
Addressing
DBD::Pg::st execute failed: ERROR: missing FROM-clause entry for table "rhn_repo_regen_queue_id_seq" at character 141
diff --git a/web/modules/rhn/RHN/DB/ChannelEditor.pm b/web/modules/rhn/RHN/DB/ChannelEditor.pm
index 4977009..8549757 100644
--- a/web/modules/rhn/RHN/DB/ChannelEditor.pm
+++ b/web/modules/rhn/RHN/DB/ChannelEditor.pm
@@ -293,7 +293,7 @@ EOQ
INSERT
INTO rhnRepoRegenQueue
(id, channel_label, client, reason, force, bypass_filters, next_action, created, modified)
-VALUES (rhn_repo_regen_queue_id_seq.nextval,
+VALUES (null,
:label, 'perl-web::clone_channel_packages', NULL, 'N', 'N', sysdate, sysdate, sysdate)
EOQ
commit b950aa91472dfde360b26b5495c3f207b0bf56ba
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 12:09:18 2010 +0200
As PostgreSQL does not support table aliases in inserts, remove them.
diff --git a/web/modules/rhn/RHN/DB/TableClass.pm b/web/modules/rhn/RHN/DB/TableClass.pm
index 525485e..bb627f7 100644
--- a/web/modules/rhn/RHN/DB/TableClass.pm
+++ b/web/modules/rhn/RHN/DB/TableClass.pm
@@ -145,9 +145,12 @@ sub insert_query {
return '' unless grep { exists $changed_fields{$_} } $self->column_names;
+ my $remove_alias = "$self->{alias}.";
my $ret;
- $ret .= "INSERT INTO $self->{name} $self->{alias}\n (";
- $ret .= join(", ", grep { exists $changed_fields{$_} } $self->column_names);
+ $ret .= "INSERT INTO $self->{name}\n (";
+ $ret .= join(", ",
+ map { ($remove_alias eq substr($_, 0, length($remove_alias))) ? substr($_, length($remove_alias)) : $_ }
+ grep { exists $changed_fields{$_} } $self->column_names);
$ret .= ") VALUES (";
$ret .= join(", ", map { $self->type_to_placeholder($_) }
grep { exists $changed_fields{$_} } map { "$_" } $self->column_names);
13 years, 6 months
5 commits - client/tools java/code
by Miroslav Suchý
client/tools/spacewalk-remote-utils/spacewalk-remote-utils.spec | 8
java/code/src/com/redhat/rhn/taskomatic/task/repomd/ChannelRepodataWorker.java | 19
java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebRepositoryWriter.java | 91 +
java/code/src/com/redhat/rhn/taskomatic/task/repomd/RepositoryWriter.java | 540 ----------
java/code/src/com/redhat/rhn/taskomatic/task/repomd/RpmRepositoryWriter.java | 472 ++++++++
5 files changed, 630 insertions(+), 500 deletions(-)
New commits:
commit 8c177fa5d22e80744fab303d5ef594ad8c03d01b
Author: Simon Lukasik <slukasik(a)redhat.com>
Date: Sat Oct 2 11:55:41 2010 +0200
Remove all from cache, not only rpm specific metadata.
diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/RepositoryWriter.java b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/RepositoryWriter.java
index b03d419..f01d5f2 100644
--- a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/RepositoryWriter.java
+++ b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/RepositoryWriter.java
@@ -64,7 +64,7 @@ public abstract class RepositoryWriter {
public abstract String getCompsFilePath(Channel channel);
/**
- * Deletes repomd files
+ * Deletes repository cache files
* @param channelLabelToProcess channel label
* @param deleteDir directory to delete
*/
@@ -72,28 +72,17 @@ public abstract class RepositoryWriter {
log.info("Removing " + channelLabelToProcess);
String prefix = mountPoint + File.separator + pathPrefix + File.separator +
channelLabelToProcess;
- File primary = new File(prefix + File.separator + "primary.xml.gz");
- File filelists = new File(prefix + File.separator + "filelists.xml.gz");
- File other = new File(prefix + File.separator + "other.xml.gz");
- File repomd = new File(prefix + File.separator + "repomd.xml");
- File updateinfo = new File(prefix + File.separator + "updateinfo.xml.gz");
- File norepo = new File(prefix + File.separator + "noyumrepo.txt");
File theDirectory = new File(prefix);
- if (!primary.delete()) {
- log.info("Couldn't remove " + primary.getAbsolutePath());
- }
- if (!filelists.delete()) {
- log.info("Couldn't remove " + filelists.getAbsolutePath());
- }
- if (!other.delete()) {
- log.info("Couldn't remove " + other.getAbsolutePath());
- }
- if (!repomd.delete()) {
- log.info("Couldn't remove " + repomd.getAbsolutePath());
+ String[] children = theDirectory.list();
+ if (theDirectory.isDirectory() && children != null) {
+ for (int i = 0; i < children.length; i ++) {
+ File file = new File(prefix + File.separator + children[i]);
+ if (!file.delete()) {
+ log.info("Couldn't remove " + file.getAbsolutePath());
+ }
+ }
}
- updateinfo.delete();
- norepo.delete();
if (deleteDir) {
if (!theDirectory.delete()) {
log.info("Couldn't remove " + prefix);
commit ad9d30c1588c434c9ee41140e11a138e6543213c
Author: Simon Lukasik <slukasik(a)redhat.com>
Date: Fri Oct 1 16:19:40 2010 +0200
Implement isChannelRepodataStale for debian channels.
diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebRepositoryWriter.java b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebRepositoryWriter.java
index d3480bf..a37a04a 100644
--- a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebRepositoryWriter.java
+++ b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebRepositoryWriter.java
@@ -15,8 +15,10 @@
package com.redhat.rhn.taskomatic.task.repomd;
import java.io.File;
+import java.util.Date;
import com.redhat.rhn.common.hibernate.HibernateFactory;
+import com.redhat.rhn.common.localization.LocalizationService;
import com.redhat.rhn.domain.channel.Channel;
import com.redhat.rhn.frontend.dto.PackageDto;
import com.redhat.rhn.manager.rhnpackage.PackageManager;
@@ -44,7 +46,17 @@ public class DebRepositoryWriter extends RepositoryWriter {
* @return repodata sanity
*/
public boolean isChannelRepodataStale(Channel channel) {
- return true;
+ File theFile = new File(mountPoint + File.separator + pathPrefix +
+ File.separator + channel.getLabel() + File.separator +
+ "Packages.gz");
+ Date fileModifiedDate = new Date(theFile.lastModified());
+ // the file Modified date should be getting set when the file
+ // is moved into the correct location.
+ log.info("File Modified Date:" + LocalizationService.getInstance().
+ formatCustomDate(fileModifiedDate));
+ log.info("Channel Modified Date:" + LocalizationService.getInstance().
+ formatCustomDate(channel.getLastModified()));
+ return !fileModifiedDate.equals(channel.getLastModified());
}
/**
commit 2e68c64438e375f40b711346259bc8533918956d
Author: Simon Lukasik <slukasik(a)redhat.com>
Date: Fri Oct 1 13:34:24 2010 +0200
Rpm and Deb metadata creation differs, moving to separate classes.
diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/ChannelRepodataWorker.java b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/ChannelRepodataWorker.java
index 5c021b5..c5162ea 100644
--- a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/ChannelRepodataWorker.java
+++ b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/ChannelRepodataWorker.java
@@ -27,6 +27,7 @@ import com.redhat.rhn.taskomatic.task.threaded.QueueWorker;
import com.redhat.rhn.taskomatic.task.threaded.TaskQueue;
import org.apache.log4j.Logger;
+import org.jfree.util.Log;
import java.util.HashMap;
import java.util.List;
@@ -58,10 +59,20 @@ public class ChannelRepodataWorker implements QueueWorker {
String mountPoint =
Config.get().getString(ConfigDefaults.REPOMD_CACHE_MOUNT_POINT, "/pub");
channelLabelToProcess = (String) workItem.get("channel_label");
- repoWriter = new RepositoryWriter(prefixPath, mountPoint);
- logger.info("Creating ChannelRepodataWorker with prefixPath(" + prefixPath +
- "), mountPoint(" + mountPoint + ")" + " for channel_label (" +
- channelLabelToProcess + ")");
+
+ // We need to find out whether to use Rpm or Debian repository
+ Channel channelToProcess = ChannelFactory.lookupByLabel(channelLabelToProcess);
+ // if the channelExists in the db still
+ if (channelToProcess != null && channelToProcess.getChannelArch()
+ .getArchType().getLabel().equalsIgnoreCase("deb")) {
+ repoWriter = new DebRepositoryWriter(prefixPath, mountPoint);
+ }
+ else {
+ repoWriter = new RpmRepositoryWriter(prefixPath, mountPoint);
+ }
+ logger.info("Creating ChannelRepodataWorker with prefixPath(" + prefixPath
+ + "), mountPoint(" + mountPoint + ")" + " for channel_label ("
+ + channelLabelToProcess + ")");
}
/**
diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebRepositoryWriter.java b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebRepositoryWriter.java
new file mode 100644
index 0000000..d3480bf
--- /dev/null
+++ b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebRepositoryWriter.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright (c) 2009--2010 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+package com.redhat.rhn.taskomatic.task.repomd;
+
+import java.io.File;
+
+import com.redhat.rhn.common.hibernate.HibernateFactory;
+import com.redhat.rhn.domain.channel.Channel;
+import com.redhat.rhn.frontend.dto.PackageDto;
+import com.redhat.rhn.manager.rhnpackage.PackageManager;
+import com.redhat.rhn.manager.task.TaskManager;
+
+/**
+*
+* @version $Rev $
+*
+*/
+public class DebRepositoryWriter extends RepositoryWriter {
+
+ /**
+ * Constructor takes in pathprefix and mountpoint
+ * @param pathPrefixIn prefix to package path
+ * @param mountPointIn mount point package resides
+ */
+ public DebRepositoryWriter(String pathPrefixIn, String mountPointIn) {
+ super(pathPrefixIn, mountPointIn);
+ }
+
+ /**
+ *
+ * @param channel channel info
+ * @return repodata sanity
+ */
+ public boolean isChannelRepodataStale(Channel channel) {
+ return true;
+ }
+
+ /**
+ * Create repository for APT
+ * @param channel
+ */
+ public void writeRepomdFiles(Channel channel) {
+ PackageManager.createRepoEntrys(channel.getId());
+
+ String prefix = mountPoint + File.separator + pathPrefix +
+ File.separator + channel.getLabel() + File.separator;
+
+ // we closed the session, so we need to reload the object
+ channel = (Channel) HibernateFactory.getSession().get(channel.getClass(),
+ channel.getId());
+ if (!new File(prefix).mkdirs() && !new File(prefix).exists()) {
+ throw new RepomdRuntimeException("Unable to create directory: " +
+ prefix);
+ }
+
+ log.info("Generating new DEB repository for channel " + channel.getLabel());
+ DebPackageWriter writer = new DebPackageWriter(channel, prefix);
+ for (PackageDto pkgDto : TaskManager.getChannelPackageDtos(channel)) {
+ writer.addPackage(pkgDto);
+ }
+ writer.generatePackagesGz();
+ }
+
+ public String getCompsFilePath(Channel channel) {
+ return null;
+ }
+}
diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/RepositoryWriter.java b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/RepositoryWriter.java
index 12fcf03..b03d419 100644
--- a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/RepositoryWriter.java
+++ b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/RepositoryWriter.java
@@ -14,53 +14,22 @@
*/
package com.redhat.rhn.taskomatic.task.repomd;
-import com.redhat.rhn.common.conf.Config;
-import com.redhat.rhn.common.conf.ConfigDefaults;
-import com.redhat.rhn.common.hibernate.HibernateFactory;
-import com.redhat.rhn.common.localization.LocalizationService;
-import com.redhat.rhn.common.util.StringUtil;
import com.redhat.rhn.domain.channel.Channel;
-import com.redhat.rhn.domain.channel.ChannelFactory;
-import com.redhat.rhn.frontend.dto.PackageDto;
-import com.redhat.rhn.manager.channel.ChannelManager;
-import com.redhat.rhn.manager.rhnpackage.PackageManager;
-import com.redhat.rhn.manager.task.TaskManager;
import org.apache.log4j.Logger;
-import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.security.DigestInputStream;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
/**
*
* @version $Rev $
*
*/
-public class RepositoryWriter {
+public abstract class RepositoryWriter {
- private static final String PRIMARY_FILE = "primary.xml.gz.new";
- private static final String FILELISTS_FILE = "filelists.xml.gz.new";
- private static final String OTHER_FILE = "other.xml.gz.new";
- private static final String REPOMD_FILE = "repomd.xml.new";
- private static final String UPDATEINFO_FILE = "updateinfo.xml.gz.new";
- private static final String NOREPO_FILE = "noyumrepo.txt";
-
- private Logger log = Logger.getLogger(RepositoryWriter.class);
- private String pathPrefix;
- private String mountPoint;
- private String checksumtype;
+ protected Logger log = Logger.getLogger(RepositoryWriter.class);
+ protected String pathPrefix;
+ protected String mountPoint;
/**
* Constructor takes in pathprefix and mountpoint
@@ -73,464 +42,62 @@ public class RepositoryWriter {
}
/**
- *
- * @param channel channel info
- * @return repodata sanity
- */
- public boolean isChannelRepodataStale(Channel channel) {
- File theFile = new File(mountPoint + File.separator + pathPrefix +
- File.separator + channel.getLabel() + File.separator +
- "repomd.xml");
- Date fileModifiedDate = new Date(theFile.lastModified());
- // the file Modified date should be getting set when the file
- // is moved into the correct location.
- log.info("File Modified Date:" + LocalizationService.getInstance().
- formatCustomDate(fileModifiedDate));
- log.info("Channel Modified Date:" + LocalizationService.getInstance().
- formatCustomDate(channel.getLastModified()));
- return !fileModifiedDate.equals(channel.getLastModified());
- }
- /**
- *
- * @param channel channelinfo for repomd file creation
- */
- public void writeRepomdFiles(Channel channel) {
-
- PackageManager.createRepoEntrys(channel.getId());
-
- String prefix = mountPoint + File.separator + pathPrefix +
- File.separator + channel.getLabel() + File.separator;
-
- // we closed the session, so we need to reload the object
- channel = (Channel) HibernateFactory.getSession().get(channel.getClass(),
- channel.getId());
- if (!new File(prefix).mkdirs() && !new File(prefix).exists()) {
- throw new RepomdRuntimeException("Unable to create directory: " +
- prefix);
- }
- if (channel.getChannelArch().getArchType().getLabel().equalsIgnoreCase("deb")) {
- log.info("Generating new DEB repository for channel " + channel.getLabel());
- generateDebRepository(channel, prefix);
- }
- else {
- // Get compatible checksumType
- this.checksumtype = channel.getChecksumTypeLabel();
- if (checksumtype == null) {
- generateBadRepo(channel, prefix);
- return;
- }
- new File(prefix + NOREPO_FILE).delete();
- log.info("Checksum Type Value: " + this.checksumtype);
-
- // java.security.MessageDigest recognizes:
- // MD2, MD5, SHA-1, SHA-256, SHA-384, SHA-512
- String checksumAlgo = this.checksumtype;
- if (checksumAlgo.toUpperCase().startsWith("SHA")) {
- checksumAlgo = this.checksumtype.substring(0, 3) + "-" +
- this.checksumtype.substring(3);
- }
- // translate sha1 to sha for xml repo files
- String checksumLabel = this.checksumtype;
- if (checksumLabel.equals("sha1")) {
- checksumLabel = "sha";
- }
-
- log.info("Generating new repository metatada for channel '" +
- channel.getLabel() + "' " + channel.getPackageCount() +
- " packages, " + channel.getErrataCount() + " updates");
-
- CompressingDigestOutputWriter primaryFile;
- CompressingDigestOutputWriter filelistsFile;
- CompressingDigestOutputWriter otherFile;
-
- try {
- primaryFile = new CompressingDigestOutputWriter(
- new FileOutputStream(prefix + PRIMARY_FILE),
- checksumAlgo);
- filelistsFile = new CompressingDigestOutputWriter(
- new FileOutputStream(prefix + FILELISTS_FILE),
- checksumAlgo);
- otherFile = new CompressingDigestOutputWriter(
- new FileOutputStream(prefix + OTHER_FILE), checksumAlgo);
- }
- catch (IOException e) {
- throw new RepomdRuntimeException(e);
- }
- catch (NoSuchAlgorithmException e) {
- throw new RepomdRuntimeException(e);
- }
-
- BufferedWriter primaryBufferedWriter = new BufferedWriter(
- new OutputStreamWriter(primaryFile));
- BufferedWriter filelistsBufferedWriter = new BufferedWriter(
- new OutputStreamWriter(filelistsFile));
- BufferedWriter otherBufferedWriter = new BufferedWriter(
- new OutputStreamWriter(otherFile));
- PrimaryXmlWriter primary = new PrimaryXmlWriter(
- primaryBufferedWriter);
- FilelistsXmlWriter filelists = new FilelistsXmlWriter(
- filelistsBufferedWriter);
- OtherXmlWriter other = new OtherXmlWriter(otherBufferedWriter);
- Date start = new Date();
-
- primary.begin(channel);
- filelists.begin(channel);
- other.begin(channel);
-
- for (PackageDto pkgDto : TaskManager.getChannelPackageDtos(channel)) {
- primary.addPackage(pkgDto);
- filelists.addPackage(pkgDto);
- other.addPackage(pkgDto);
- try {
- primaryFile.flush();
- filelistsFile.flush();
- otherFile.flush();
- }
- catch (IOException e) {
- throw new RepomdRuntimeException(e);
- }
- }
- primary.end();
- filelists.end();
- other.end();
- try {
- primaryBufferedWriter.close();
- filelistsBufferedWriter.close();
- otherBufferedWriter.close();
- }
- catch (IOException e) {
- throw new RepomdRuntimeException(e);
- }
-
- RepomdIndexData primaryData = new RepomdIndexData(primaryFile
- .getCompressedChecksum(), primaryFile
- .getUncompressedChecksum(), channel.getLastModified());
- RepomdIndexData filelistsData = new RepomdIndexData(filelistsFile
- .getCompressedChecksum(), filelistsFile
- .getUncompressedChecksum(), channel.getLastModified());
- RepomdIndexData otherData = new RepomdIndexData(otherFile
- .getCompressedChecksum(), otherFile
- .getUncompressedChecksum(), channel.getLastModified());
-
- log.info("Starting updateinfo generation for '" + channel.getLabel() + '"');
- log.info("Checksum Type Value for generate updateinfo " + this.checksumtype);
- RepomdIndexData updateinfoData = generateUpdateinfo(channel,
- prefix, checksumAlgo);
-
- RepomdIndexData groupsData = loadCompsFile(channel, checksumAlgo);
-
- // Set the type so yum can read and perform checksum
- primaryData.setType(checksumLabel);
- filelistsData.setType(checksumLabel);
- otherData.setType(checksumLabel);
- if (updateinfoData != null) {
- updateinfoData.setType(checksumLabel);
- }
-
- if (groupsData != null) {
- groupsData.setType(checksumLabel);
- }
-
- log.info("Primary xml's type: " + primaryData.getType());
- log.info("filelists xml's type: " + filelistsData.getType());
- log.info("other xml's type: " + otherData.getType());
-
- FileWriter indexFile;
-
- try {
- indexFile = new FileWriter(prefix + REPOMD_FILE);
- }
- catch (IOException e) {
- throw new RepomdRuntimeException(e);
- }
-
- RepomdIndexWriter index = new RepomdIndexWriter(indexFile, primaryData,
- filelistsData, otherData, updateinfoData, groupsData);
-
- index.writeRepomdIndex();
-
- try {
- indexFile.close();
- }
- catch (IOException e) {
- throw new RepomdRuntimeException(e);
- }
-
- renameFiles(prefix, channel.getLastModified().getTime(),
- updateinfoData != null);
-
- log.info("Repository metadata generation for '" +
- channel.getLabel() + "' finished in " +
- (int) (new Date().getTime() - start.getTime()) / 1000 + " seconds");
- }
- }
-
- /**
- * Deletes existing repo and generates file stating that no repo was generated
- * @param channel the channel to do this for
- * @param prefix the directory prefix
- */
- private void generateBadRepo(Channel channel, String prefix) {
- log.warn("No repo will be generated for channel " + channel.getLabel());
- deleteRepomdFiles(channel.getLabel(), false);
- try {
- FileWriter norepo = new FileWriter(prefix + NOREPO_FILE);
- norepo.write("No repo will be generated for channel " +
- channel.getLabel() + ".\n");
- norepo.close();
- }
- catch (IOException e) {
- log.warn("Cannot create " + NOREPO_FILE + " file.");
- }
- return;
- }
-
- /**
- * Create repository for APT
- * @param channel
- */
- private void generateDebRepository(Channel channel, String prefix) {
- DebPackageWriter writer = new DebPackageWriter(channel, prefix);
- for (PackageDto pkgDto : TaskManager.getChannelPackageDtos(channel)) {
- writer.addPackage(pkgDto);
- }
- writer.generatePackagesGz();
- }
-
- private String getCompsRelativeFilename(Channel channel) {
- String relativeFilename = null;
-
- if (channel.getComps() == null) {
- relativeFilename = getCompsFilePath(channel);
- }
- else {
- relativeFilename = channel.getComps().getRelativeFilename();
- }
-
- // if we didn't find anything, let's check channel's original
- if (relativeFilename == null && channel.isCloned()) {
- // use a hack not to use ClonedChannel and it's getOriginal() method
- Long originalChannelId = ChannelManager.lookupOriginalId(channel);
- Channel originalChannel = ChannelFactory.lookupById(originalChannelId);
- return getCompsRelativeFilename(originalChannel);
- }
-
- return relativeFilename;
- }
-
- /**
- *
- * @param channel channel indo
- * @param checksumAlgo checksum algorithm
- * @return repomd index for given channel
- */
- private RepomdIndexData loadCompsFile(Channel channel, String checksumAlgo) {
- String compsMount = Config.get().getString(ConfigDefaults.MOUNT_POINT);
- String relativeFilename = getCompsRelativeFilename(channel);
-
- if (relativeFilename == null) {
- return null;
- }
-
- File compsFile = new File(compsMount + File.separator + relativeFilename);
- FileInputStream stream;
- try {
- stream = new FileInputStream(compsFile);
- }
- catch (FileNotFoundException e) {
- return null;
- }
-
- DigestInputStream digestStream;
- try {
- digestStream = new DigestInputStream(stream, MessageDigest
- .getInstance(checksumAlgo));
- }
- catch (NoSuchAlgorithmException nsae) {
- throw new RepomdRuntimeException(nsae);
- }
- byte[] bytes = new byte[10];
-
- try {
- while (digestStream.read(bytes) != -1) {
- // no-op
- }
- }
- catch (IOException e) {
- return null;
- }
-
- Date timeStamp = new Date(compsFile.lastModified());
-
- return new RepomdIndexData(StringUtil.getHexString(digestStream
- .getMessageDigest().digest()), null, timeStamp);
- }
-
- /**
- * TODO: This static comps paths should go away once
- * we can get the paths directly from hosted through
- * satellite-sync and only limit to supporting cloned.
- * @param channel channel object
- * @return compsPath comps file path
+ *
+ * @param channel channel info
+ * @return repodata sanity
*/
- public String getCompsFilePath(Channel channel) {
- String compsPath = null;
-
- Map<String, String> compsMapping = new HashMap<String, String>();
- String rootClientPath = "/rhn/kickstart/ks-rhel-x86_64-client-5";
- String rootServerPath = "/rhn/kickstart/ks-rhel-x86_64-server-5";
- compsMapping.put("rhel-x86_64-client-5",
- rootClientPath + "/Client/repodata/comps-rhel5-client-core.xml");
- compsMapping.put("rhel-x86_64-client-vt-5",
- rootClientPath + "/VT/repodata/comps-rhel5-vt.xml");
- compsMapping.put("rhel-x86_64-client-workstation-5",
- rootClientPath + "/Workstation/repodata/comps-rhel5-client-workstation.xml");
- compsMapping.put("rhel-x86_64-server-5",
- rootServerPath + "/Server/repodata/comps-rhel5-server-core.xml");
- compsMapping.put("rhel-x86_64-server-vt-5",
- rootServerPath + "/VT/repodata/comps-rhel5-vt.xml");
- compsMapping.put("rhel-x86_64-server-cluster-5",
- rootServerPath + "/Cluster/repodata/comps-rhel5-cluster.xml");
- compsMapping.put("rhel-x86_64-server-cluster-storage-5",
- rootServerPath + "/ClusterStorage/repodata/comps-rhel5-cluster-st.xml");
-
- String[] arches = {"i386", "ia64", "s390x", "ppc"};
- Map<String, String> newCompsmap = new HashMap<String, String>();
- for (String k : compsMapping.keySet()) {
- for (String arch : arches) {
- newCompsmap.put(k.replace("x86_64", arch),
- compsMapping.get(k).replace("x86_64", arch));
- }
- }
- compsMapping.putAll(newCompsmap);
-
- if (compsMapping.containsKey(channel.getLabel())) {
- compsPath = compsMapping.get(channel.getLabel());
- }
-
- return compsPath;
- }
+ public abstract boolean isChannelRepodataStale(Channel channel);
/**
- * Generates update info for given channel
- * @param channel channel info
- * @param prefix repodata file prefix
- * @param checksumtype checksum type
- * @return repodata index
- */
- private RepomdIndexData generateUpdateinfo(Channel channel, String prefix,
- String checksumtypeIn) {
-
- if (channel.getErrataCount() == 0) {
- return null;
- }
-
- CompressingDigestOutputWriter updateinfoFile;
- try {
- updateinfoFile = new CompressingDigestOutputWriter(
- new FileOutputStream(prefix + UPDATEINFO_FILE), checksumtypeIn);
- }
- catch (FileNotFoundException e) {
- throw new RepomdRuntimeException(e);
- }
- catch (NoSuchAlgorithmException e) {
- throw new RepomdRuntimeException(e);
- }
- catch (IOException e) {
- throw new RepomdRuntimeException(e);
- }
- BufferedWriter updateinfoBufferedWriter = new BufferedWriter(
- new OutputStreamWriter(updateinfoFile));
- UpdateInfoWriter updateinfo = new UpdateInfoWriter(
- updateinfoBufferedWriter);
- updateinfo.getUpdateInfo(channel);
- try {
- updateinfoBufferedWriter.close();
- }
- catch (IOException e) {
- throw new RepomdRuntimeException(e);
- }
-
- RepomdIndexData updateinfoData = new RepomdIndexData(updateinfoFile
- .getCompressedChecksum(), updateinfoFile
- .getUncompressedChecksum(), channel.getLastModified());
- return updateinfoData;
- }
-
- /**
- * Renames the repo cache files
- * @param prefix path prefix
- * @param lastModified file last_modified
- * @param doUpdateinfo
- */
- private void renameFiles(String prefix, Long lastModified,
- Boolean doUpdateinfo) {
- File primary = new File(prefix + PRIMARY_FILE);
- File filelists = new File(prefix + FILELISTS_FILE);
- File other = new File(prefix + OTHER_FILE);
- File repomd = new File(prefix + REPOMD_FILE);
-
- File updateinfo = null;
- if (doUpdateinfo) {
- updateinfo = new File(prefix + UPDATEINFO_FILE);
- }
-
- if (doUpdateinfo) {
- updateinfo.setLastModified(lastModified);
- }
-
- primary.setLastModified(lastModified);
- filelists.setLastModified(lastModified);
- other.setLastModified(lastModified);
- repomd.setLastModified(lastModified);
-
- if (doUpdateinfo) {
- updateinfo.renameTo(new File(prefix + "updateinfo.xml.gz"));
- }
-
- primary.renameTo(new File(prefix + "primary.xml.gz"));
- filelists.renameTo(new File(prefix + "filelists.xml.gz"));
- other.renameTo(new File(prefix + "other.xml.gz"));
- repomd.renameTo(new File(prefix + "repomd.xml"));
-
- }
-
- /**
- * Deletes repomd files
- * @param channelLabelToProcess channel label
- * @param deleteDir directory to delete
- */
- public void deleteRepomdFiles(String channelLabelToProcess, boolean deleteDir) {
- log.info("Removing " + channelLabelToProcess);
- String prefix = mountPoint + File.separator + pathPrefix + File.separator +
- channelLabelToProcess;
- File primary = new File(prefix + File.separator + "primary.xml.gz");
- File filelists = new File(prefix + File.separator + "filelists.xml.gz");
- File other = new File(prefix + File.separator + "other.xml.gz");
- File repomd = new File(prefix + File.separator + "repomd.xml");
- File updateinfo = new File(prefix + File.separator + "updateinfo.xml.gz");
- File norepo = new File(prefix + File.separator + NOREPO_FILE);
- File theDirectory = new File(prefix);
-
- if (!primary.delete()) {
- log.info("Couldn't remove " + primary.getAbsolutePath());
- }
- if (!filelists.delete()) {
- log.info("Couldn't remove " + filelists.getAbsolutePath());
- }
- if (!other.delete()) {
- log.info("Couldn't remove " + other.getAbsolutePath());
- }
- if (!repomd.delete()) {
- log.info("Couldn't remove " + repomd.getAbsolutePath());
- }
- updateinfo.delete();
- norepo.delete();
- if (deleteDir) {
- if (!theDirectory.delete()) {
- log.info("Couldn't remove " + prefix);
- }
- }
- }
-
+ *
+ * @param channel channelinfo for repomd file creation
+ */
+ public abstract void writeRepomdFiles(Channel channel);
+
+ /**
+ * TODO: This static comps paths should go away once
+ * we can get the paths directly from hosted through
+ * satellite-sync and only limit to supporting cloned.
+ * @param channel channel object
+ * @return compsPath comps file path
+ */
+ public abstract String getCompsFilePath(Channel channel);
+
+ /**
+ * Deletes repomd files
+ * @param channelLabelToProcess channel label
+ * @param deleteDir directory to delete
+ */
+ public void deleteRepomdFiles(String channelLabelToProcess, boolean deleteDir) {
+ log.info("Removing " + channelLabelToProcess);
+ String prefix = mountPoint + File.separator + pathPrefix + File.separator +
+ channelLabelToProcess;
+ File primary = new File(prefix + File.separator + "primary.xml.gz");
+ File filelists = new File(prefix + File.separator + "filelists.xml.gz");
+ File other = new File(prefix + File.separator + "other.xml.gz");
+ File repomd = new File(prefix + File.separator + "repomd.xml");
+ File updateinfo = new File(prefix + File.separator + "updateinfo.xml.gz");
+ File norepo = new File(prefix + File.separator + "noyumrepo.txt");
+ File theDirectory = new File(prefix);
+
+ if (!primary.delete()) {
+ log.info("Couldn't remove " + primary.getAbsolutePath());
+ }
+ if (!filelists.delete()) {
+ log.info("Couldn't remove " + filelists.getAbsolutePath());
+ }
+ if (!other.delete()) {
+ log.info("Couldn't remove " + other.getAbsolutePath());
+ }
+ if (!repomd.delete()) {
+ log.info("Couldn't remove " + repomd.getAbsolutePath());
+ }
+ updateinfo.delete();
+ norepo.delete();
+ if (deleteDir) {
+ if (!theDirectory.delete()) {
+ log.info("Couldn't remove " + prefix);
+ }
+ }
+ }
}
diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/RpmRepositoryWriter.java b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/RpmRepositoryWriter.java
new file mode 100644
index 0000000..27cf51a
--- /dev/null
+++ b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/RpmRepositoryWriter.java
@@ -0,0 +1,472 @@
+/**
+ * Copyright (c) 2009--2010 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+package com.redhat.rhn.taskomatic.task.repomd;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.security.DigestInputStream;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.redhat.rhn.common.conf.Config;
+import com.redhat.rhn.common.conf.ConfigDefaults;
+import com.redhat.rhn.common.hibernate.HibernateFactory;
+import com.redhat.rhn.common.localization.LocalizationService;
+import com.redhat.rhn.common.util.StringUtil;
+import com.redhat.rhn.domain.channel.Channel;
+import com.redhat.rhn.domain.channel.ChannelFactory;
+import com.redhat.rhn.frontend.dto.PackageDto;
+import com.redhat.rhn.manager.channel.ChannelManager;
+import com.redhat.rhn.manager.rhnpackage.PackageManager;
+import com.redhat.rhn.manager.task.TaskManager;
+
+/**
+*
+* @version $Rev $
+*
+*/
+public class RpmRepositoryWriter extends RepositoryWriter {
+
+ private static final String PRIMARY_FILE = "primary.xml.gz.new";
+ private static final String FILELISTS_FILE = "filelists.xml.gz.new";
+ private static final String OTHER_FILE = "other.xml.gz.new";
+ private static final String REPOMD_FILE = "repomd.xml.new";
+ private static final String UPDATEINFO_FILE = "updateinfo.xml.gz.new";
+ private static final String NOREPO_FILE = "noyumrepo.txt";
+
+ private String checksumtype;
+
+ /**
+ * Constructor takes in pathprefix and mountpoint
+ * @param pathPrefixIn prefix to package path
+ * @param mountPointIn mount point package resides
+ */
+ public RpmRepositoryWriter(String pathPrefixIn, String mountPointIn) {
+ super(pathPrefixIn, mountPointIn);
+ }
+
+ /**
+ *
+ * @param channel channel info
+ * @return repodata sanity
+ */
+ public boolean isChannelRepodataStale(Channel channel) {
+ File theFile = new File(mountPoint + File.separator + pathPrefix +
+ File.separator + channel.getLabel() + File.separator +
+ "repomd.xml");
+ Date fileModifiedDate = new Date(theFile.lastModified());
+ // the file Modified date should be getting set when the file
+ // is moved into the correct location.
+ log.info("File Modified Date:" + LocalizationService.getInstance().
+ formatCustomDate(fileModifiedDate));
+ log.info("Channel Modified Date:" + LocalizationService.getInstance().
+ formatCustomDate(channel.getLastModified()));
+ return !fileModifiedDate.equals(channel.getLastModified());
+ }
+
+ /**
+ *
+ * @param channel channelinfo for repomd file creation
+ */
+ public void writeRepomdFiles(Channel channel) {
+ PackageManager.createRepoEntrys(channel.getId());
+
+ String prefix = mountPoint + File.separator + pathPrefix +
+ File.separator + channel.getLabel() + File.separator;
+
+ // we closed the session, so we need to reload the object
+ channel = (Channel) HibernateFactory.getSession().get(channel.getClass(),
+ channel.getId());
+ if (!new File(prefix).mkdirs() && !new File(prefix).exists()) {
+ throw new RepomdRuntimeException("Unable to create directory: " +
+ prefix);
+ }
+ // Get compatible checksumType
+ this.checksumtype = channel.getChecksumTypeLabel();
+ if (checksumtype == null) {
+ generateBadRepo(channel, prefix);
+ return;
+ }
+ new File(prefix + NOREPO_FILE).delete();
+ log.info("Checksum Type Value: " + this.checksumtype);
+
+ // java.security.MessageDigest recognizes:
+ // MD2, MD5, SHA-1, SHA-256, SHA-384, SHA-512
+ String checksumAlgo = this.checksumtype;
+ if (checksumAlgo.toUpperCase().startsWith("SHA")) {
+ checksumAlgo = this.checksumtype.substring(0, 3) + "-" +
+ this.checksumtype.substring(3);
+ }
+ // translate sha1 to sha for xml repo files
+ String checksumLabel = this.checksumtype;
+ if (checksumLabel.equals("sha1")) {
+ checksumLabel = "sha";
+ }
+
+ log.info("Generating new repository metatada for channel '" +
+ channel.getLabel() + "' " + channel.getPackageCount() +
+ " packages, " + channel.getErrataCount() + " updates");
+
+ CompressingDigestOutputWriter primaryFile;
+ CompressingDigestOutputWriter filelistsFile;
+ CompressingDigestOutputWriter otherFile;
+
+ try {
+ primaryFile = new CompressingDigestOutputWriter(
+ new FileOutputStream(prefix + PRIMARY_FILE),
+ checksumAlgo);
+ filelistsFile = new CompressingDigestOutputWriter(
+ new FileOutputStream(prefix + FILELISTS_FILE),
+ checksumAlgo);
+ otherFile = new CompressingDigestOutputWriter(
+ new FileOutputStream(prefix + OTHER_FILE), checksumAlgo);
+ }
+ catch (IOException e) {
+ throw new RepomdRuntimeException(e);
+ }
+ catch (NoSuchAlgorithmException e) {
+ throw new RepomdRuntimeException(e);
+ }
+
+ BufferedWriter primaryBufferedWriter = new BufferedWriter(
+ new OutputStreamWriter(primaryFile));
+ BufferedWriter filelistsBufferedWriter = new BufferedWriter(
+ new OutputStreamWriter(filelistsFile));
+ BufferedWriter otherBufferedWriter = new BufferedWriter(
+ new OutputStreamWriter(otherFile));
+ PrimaryXmlWriter primary = new PrimaryXmlWriter(
+ primaryBufferedWriter);
+ FilelistsXmlWriter filelists = new FilelistsXmlWriter(
+ filelistsBufferedWriter);
+ OtherXmlWriter other = new OtherXmlWriter(otherBufferedWriter);
+ Date start = new Date();
+
+ primary.begin(channel);
+ filelists.begin(channel);
+ other.begin(channel);
+
+ for (PackageDto pkgDto : TaskManager.getChannelPackageDtos(channel)) {
+ primary.addPackage(pkgDto);
+ filelists.addPackage(pkgDto);
+ other.addPackage(pkgDto);
+ try {
+ primaryFile.flush();
+ filelistsFile.flush();
+ otherFile.flush();
+ }
+ catch (IOException e) {
+ throw new RepomdRuntimeException(e);
+ }
+ }
+ primary.end();
+ filelists.end();
+ other.end();
+ try {
+ primaryBufferedWriter.close();
+ filelistsBufferedWriter.close();
+ otherBufferedWriter.close();
+ }
+ catch (IOException e) {
+ throw new RepomdRuntimeException(e);
+ }
+
+ RepomdIndexData primaryData = new RepomdIndexData(primaryFile
+ .getCompressedChecksum(), primaryFile
+ .getUncompressedChecksum(), channel.getLastModified());
+ RepomdIndexData filelistsData = new RepomdIndexData(filelistsFile
+ .getCompressedChecksum(), filelistsFile
+ .getUncompressedChecksum(), channel.getLastModified());
+ RepomdIndexData otherData = new RepomdIndexData(otherFile
+ .getCompressedChecksum(), otherFile
+ .getUncompressedChecksum(), channel.getLastModified());
+
+ log.info("Starting updateinfo generation for '" + channel.getLabel() + '"');
+ log.info("Checksum Type Value for generate updateinfo " + this.checksumtype);
+ RepomdIndexData updateinfoData = generateUpdateinfo(channel,
+ prefix, checksumAlgo);
+
+ RepomdIndexData groupsData = loadCompsFile(channel, checksumAlgo);
+
+ // Set the type so yum can read and perform checksum
+ primaryData.setType(checksumLabel);
+ filelistsData.setType(checksumLabel);
+ otherData.setType(checksumLabel);
+ if (updateinfoData != null) {
+ updateinfoData.setType(checksumLabel);
+ }
+
+ if (groupsData != null) {
+ groupsData.setType(checksumLabel);
+ }
+
+ log.info("Primary xml's type: " + primaryData.getType());
+ log.info("filelists xml's type: " + filelistsData.getType());
+ log.info("other xml's type: " + otherData.getType());
+
+ FileWriter indexFile;
+
+ try {
+ indexFile = new FileWriter(prefix + REPOMD_FILE);
+ }
+ catch (IOException e) {
+ throw new RepomdRuntimeException(e);
+ }
+
+ RepomdIndexWriter index = new RepomdIndexWriter(indexFile, primaryData,
+ filelistsData, otherData, updateinfoData, groupsData);
+
+ index.writeRepomdIndex();
+
+ try {
+ indexFile.close();
+ }
+ catch (IOException e) {
+ throw new RepomdRuntimeException(e);
+ }
+
+ renameFiles(prefix, channel.getLastModified().getTime(),
+ updateinfoData != null);
+
+ log.info("Repository metadata generation for '" +
+ channel.getLabel() + "' finished in " +
+ (int) (new Date().getTime() - start.getTime()) / 1000 + " seconds");
+ }
+
+ /**
+ * Deletes existing repo and generates file stating that no repo was generated
+ * @param channel the channel to do this for
+ * @param prefix the directory prefix
+ */
+ private void generateBadRepo(Channel channel, String prefix) {
+ log.warn("No repo will be generated for channel " + channel.getLabel());
+ deleteRepomdFiles(channel.getLabel(), false);
+ try {
+ FileWriter norepo = new FileWriter(prefix + NOREPO_FILE);
+ norepo.write("No repo will be generated for channel " +
+ channel.getLabel() + ".\n");
+ norepo.close();
+ }
+ catch (IOException e) {
+ log.warn("Cannot create " + NOREPO_FILE + " file.");
+ }
+ return;
+ }
+
+ private String getCompsRelativeFilename(Channel channel) {
+ String relativeFilename = null;
+
+ if (channel.getComps() == null) {
+ relativeFilename = getCompsFilePath(channel);
+ }
+ else {
+ relativeFilename = channel.getComps().getRelativeFilename();
+ }
+
+ // if we didn't find anything, let's check channel's original
+ if (relativeFilename == null && channel.isCloned()) {
+ // use a hack not to use ClonedChannel and it's getOriginal() method
+ Long originalChannelId = ChannelManager.lookupOriginalId(channel);
+ Channel originalChannel = ChannelFactory.lookupById(originalChannelId);
+ return getCompsRelativeFilename(originalChannel);
+ }
+
+ return relativeFilename;
+ }
+
+ /**
+ *
+ * @param channel channel indo
+ * @param checksumAlgo checksum algorithm
+ * @return repomd index for given channel
+ */
+ private RepomdIndexData loadCompsFile(Channel channel, String checksumAlgo) {
+ String compsMount = Config.get().getString(ConfigDefaults.MOUNT_POINT);
+ String relativeFilename = getCompsRelativeFilename(channel);
+
+ if (relativeFilename == null) {
+ return null;
+ }
+
+ File compsFile = new File(compsMount + File.separator + relativeFilename);
+ FileInputStream stream;
+ try {
+ stream = new FileInputStream(compsFile);
+ }
+ catch (FileNotFoundException e) {
+ return null;
+ }
+
+ DigestInputStream digestStream;
+ try {
+ digestStream = new DigestInputStream(stream, MessageDigest
+ .getInstance(checksumAlgo));
+ }
+ catch (NoSuchAlgorithmException nsae) {
+ throw new RepomdRuntimeException(nsae);
+ }
+ byte[] bytes = new byte[10];
+
+ try {
+ while (digestStream.read(bytes) != -1) {
+ // no-op
+ }
+ }
+ catch (IOException e) {
+ return null;
+ }
+
+ Date timeStamp = new Date(compsFile.lastModified());
+
+ return new RepomdIndexData(StringUtil.getHexString(digestStream
+ .getMessageDigest().digest()), null, timeStamp);
+ }
+
+ /**
+ * TODO: This static comps paths should go away once
+ * we can get the paths directly from hosted through
+ * satellite-sync and only limit to supporting cloned.
+ * @param channel channel object
+ * @return compsPath comps file path
+ */
+ public String getCompsFilePath(Channel channel) {
+ String compsPath = null;
+
+ Map<String, String> compsMapping = new HashMap<String, String>();
+ String rootClientPath = "/rhn/kickstart/ks-rhel-x86_64-client-5";
+ String rootServerPath = "/rhn/kickstart/ks-rhel-x86_64-server-5";
+ compsMapping.put("rhel-x86_64-client-5",
+ rootClientPath + "/Client/repodata/comps-rhel5-client-core.xml");
+ compsMapping.put("rhel-x86_64-client-vt-5",
+ rootClientPath + "/VT/repodata/comps-rhel5-vt.xml");
+ compsMapping.put("rhel-x86_64-client-workstation-5",
+ rootClientPath + "/Workstation/repodata/comps-rhel5-client-workstation.xml");
+ compsMapping.put("rhel-x86_64-server-5",
+ rootServerPath + "/Server/repodata/comps-rhel5-server-core.xml");
+ compsMapping.put("rhel-x86_64-server-vt-5",
+ rootServerPath + "/VT/repodata/comps-rhel5-vt.xml");
+ compsMapping.put("rhel-x86_64-server-cluster-5",
+ rootServerPath + "/Cluster/repodata/comps-rhel5-cluster.xml");
+ compsMapping.put("rhel-x86_64-server-cluster-storage-5",
+ rootServerPath + "/ClusterStorage/repodata/comps-rhel5-cluster-st.xml");
+
+ String[] arches = {"i386", "ia64", "s390x", "ppc"};
+ Map<String, String> newCompsmap = new HashMap<String, String>();
+ for (String k : compsMapping.keySet()) {
+ for (String arch : arches) {
+ newCompsmap.put(k.replace("x86_64", arch),
+ compsMapping.get(k).replace("x86_64", arch));
+ }
+ }
+ compsMapping.putAll(newCompsmap);
+
+ if (compsMapping.containsKey(channel.getLabel())) {
+ compsPath = compsMapping.get(channel.getLabel());
+ }
+
+ return compsPath;
+ }
+
+ /**
+ * Generates update info for given channel
+ * @param channel channel info
+ * @param prefix repodata file prefix
+ * @param checksumtype checksum type
+ * @return repodata index
+ */
+ private RepomdIndexData generateUpdateinfo(Channel channel, String prefix,
+ String checksumtypeIn) {
+
+ if (channel.getErrataCount() == 0) {
+ return null;
+ }
+
+ CompressingDigestOutputWriter updateinfoFile;
+ try {
+ updateinfoFile = new CompressingDigestOutputWriter(
+ new FileOutputStream(prefix + UPDATEINFO_FILE), checksumtypeIn);
+ }
+ catch (FileNotFoundException e) {
+ throw new RepomdRuntimeException(e);
+ }
+ catch (NoSuchAlgorithmException e) {
+ throw new RepomdRuntimeException(e);
+ }
+ catch (IOException e) {
+ throw new RepomdRuntimeException(e);
+ }
+ BufferedWriter updateinfoBufferedWriter = new BufferedWriter(
+ new OutputStreamWriter(updateinfoFile));
+ UpdateInfoWriter updateinfo = new UpdateInfoWriter(
+ updateinfoBufferedWriter);
+ updateinfo.getUpdateInfo(channel);
+ try {
+ updateinfoBufferedWriter.close();
+ }
+ catch (IOException e) {
+ throw new RepomdRuntimeException(e);
+ }
+
+ RepomdIndexData updateinfoData = new RepomdIndexData(updateinfoFile
+ .getCompressedChecksum(), updateinfoFile
+ .getUncompressedChecksum(), channel.getLastModified());
+ return updateinfoData;
+ }
+
+ /**
+ * Renames the repo cache files
+ * @param prefix path prefix
+ * @param lastModified file last_modified
+ * @param doUpdateinfo
+ */
+ private void renameFiles(String prefix, Long lastModified,
+ Boolean doUpdateinfo) {
+ File primary = new File(prefix + PRIMARY_FILE);
+ File filelists = new File(prefix + FILELISTS_FILE);
+ File other = new File(prefix + OTHER_FILE);
+ File repomd = new File(prefix + REPOMD_FILE);
+
+ File updateinfo = null;
+ if (doUpdateinfo) {
+ updateinfo = new File(prefix + UPDATEINFO_FILE);
+ }
+
+ if (doUpdateinfo) {
+ updateinfo.setLastModified(lastModified);
+ }
+
+ primary.setLastModified(lastModified);
+ filelists.setLastModified(lastModified);
+ other.setLastModified(lastModified);
+ repomd.setLastModified(lastModified);
+
+ if (doUpdateinfo) {
+ updateinfo.renameTo(new File(prefix + "updateinfo.xml.gz"));
+ }
+
+ primary.renameTo(new File(prefix + "primary.xml.gz"));
+ filelists.renameTo(new File(prefix + "filelists.xml.gz"));
+ other.renameTo(new File(prefix + "other.xml.gz"));
+ repomd.renameTo(new File(prefix + "repomd.xml"));
+ }
+}
commit 1134ca5bde45c3f62de5b9340d8c32dcab5af3e4
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Wed Oct 6 10:03:35 2010 +0200
correct Summary and Description
diff --git a/client/tools/spacewalk-remote-utils/spacewalk-remote-utils.spec b/client/tools/spacewalk-remote-utils/spacewalk-remote-utils.spec
index 06b15f8..454b69f 100644
--- a/client/tools/spacewalk-remote-utils/spacewalk-remote-utils.spec
+++ b/client/tools/spacewalk-remote-utils/spacewalk-remote-utils.spec
@@ -6,7 +6,7 @@
Name: spacewalk-remote-utils
Version: 1.0.4
Release: 1%{?dist}
-Summary: Utilities to interact with a Satellite or Spacewalk server remotely.
+Summary: Utilities to interact with a RHN Satellite or Spacewalk server remotely.
Group: Applications/System
License: GPLv3+
@@ -19,7 +19,7 @@ BuildRequires: python-devel
BuildRequires: docbook-utils
%description
-Utilities to interact with a Satellite or Spacewalk server remotely over XMLRPC.
+Utilities to interact with a RHN Satellite or Spacewalk server remotely over XMLRPC.
%prep
%setup -q
commit f6a84fd58b116d2311b932fea111ff3082de348d
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Wed Oct 6 10:01:47 2010 +0200
correct URL and Source0
diff --git a/client/tools/spacewalk-remote-utils/spacewalk-remote-utils.spec b/client/tools/spacewalk-remote-utils/spacewalk-remote-utils.spec
index 1849f83..06b15f8 100644
--- a/client/tools/spacewalk-remote-utils/spacewalk-remote-utils.spec
+++ b/client/tools/spacewalk-remote-utils/spacewalk-remote-utils.spec
@@ -10,8 +10,8 @@ Summary: Utilities to interact with a Satellite or Spacewalk server remotely
Group: Applications/System
License: GPLv3+
-URL: https://fedorahosted.org/spacewalk/wiki/spacecmd
-Source: %{name}-%{version}.tar.gz
+URL: http://fedorahosted.org/spacewalk
+Source: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildArch: noarch
13 years, 6 months
schema/spacewalk
by Jan Pazdziora
schema/spacewalk/upgrade/spacewalk-schema-1.1-to-spacewalk-schema-1.2/100-rhnActionType-proxy.deactivate.sql | 18 ++++++++++
1 file changed, 18 insertions(+)
New commits:
commit 2e0604e8f370e12fd61d5b5ce0dcecfb2d7f0f2a
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 11:24:01 2010 +0200
Upgrade to Satellite 5.1 from older versions put newline to proxy.deactivate record; we shall fix it now.
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.1-to-spacewalk-schema-1.2/100-rhnActionType-proxy.deactivate.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.1-to-spacewalk-schema-1.2/100-rhnActionType-proxy.deactivate.sql
new file mode 100644
index 0000000..de110a8
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.1-to-spacewalk-schema-1.2/100-rhnActionType-proxy.deactivate.sql
@@ -0,0 +1,18 @@
+--
+-- Copyright (c) 2010 Red Hat, Inc.
+--
+-- This software is licensed to you under the GNU General Public License,
+-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
+-- implied, including the implied warranties of MERCHANTABILITY or FITNESS
+-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+-- along with this software; if not, see
+-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+--
+-- Red Hat trademarks are not licensed under GPLv2. No permission is
+-- granted to use or replicate Red Hat trademarks that are incorporated
+-- in this software or its documentation.
+--
+
+update rhnActionType set name = 'Deactivate Proxy' where label = 'proxy.deactivate' and name <> 'Deactivate Proxy';
+commit;
+
13 years, 6 months
web/modules
by Jan Pazdziora
web/modules/rhn/RHN/DB.pm | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
New commits:
commit 6288d77f77d9420374560b1149ca6a875f472802
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 10:33:27 2010 +0200
Make sequence_nextval method support PostgreSQL syntax.
diff --git a/web/modules/rhn/RHN/DB.pm b/web/modules/rhn/RHN/DB.pm
index 9840462..d0b076c 100644
--- a/web/modules/rhn/RHN/DB.pm
+++ b/web/modules/rhn/RHN/DB.pm
@@ -486,8 +486,14 @@ sub sequence_nextval {
my $self = shift;
my $sequence = shift;
- my $sth = $self->prepare("SELECT $sequence.nextval FROM DUAL");
- $sth->execute;
+ my $sth;
+ if ($self->{Driver}->{Name} eq 'Pg') {
+ $sth = $self->prepare('select nextval(?)');
+ $sth->execute($sequence);
+ } else {
+ $sth = $self->prepare("SELECT $sequence.nextval FROM DUAL");
+ $sth->execute;
+ }
my ($ret) = $sth->fetchrow;
$sth->finish;
13 years, 6 months
Changes to 'refs/tags/spacewalk-java-1.2.51-1'
by Tomas Lestach
Tag 'spacewalk-java-1.2.51-1' created by Tomas Lestach <tlestach(a)redhat.com> at 2010-10-06 08:36 +0000
Tagging package [spacewalk-java] version [1.2.51-1] in directory [java/].
Changes since spacewalk-remote-utils-1.0.4-1:
Jan Pazdziora (3):
For PostgreSQL, we just select function(params) instead of begin...end block.
Use the utility sequence_nextval method instead of direct rhn_channel_id_seq.nextval, to allow portable nextval operation.
Do not reconnect with every sequence_nextval -- the $self should be usable object to call prepare on.
Justin Sherrill (3):
fixing man page name
man page formatting fix
man page formatting fix
Miroslav Suchý (1):
639449 - add package spacewalk-setup-jabberd to list of packages which should be removed in Proxy WebUI installer
Tomas Lestach (2):
640520 - removing old taskomatic static configuration
Automatic commit of package [spacewalk-java] release [1.2.51-1].
---
client/tools/spacewalk-remote-utils/spacewalk-create-channel/doc/spacewalk-create-channel.sgml | 25 ++-
client/tools/spacewalk-remote-utils/spacewalk-remote-utils.spec | 4
java/conf/default/rhn_taskomatic.conf | 74 ----------
java/spacewalk-java.spec | 5
rel-eng/packages/spacewalk-java | 2
web/html/applications/rhn-proxy/4.0/install-rhn-proxy.xml | 4
web/html/applications/rhn-proxy/4.1/install-rhn-proxy.xml | 4
web/html/applications/rhn-proxy/4.2/install-rhn-proxy.xml | 4
web/html/applications/rhn-proxy/5.0/install-rhn-proxy.xml | 4
web/html/applications/rhn-proxy/5.1/install-rhn-proxy.xml | 4
web/html/applications/rhn-proxy/5.2/install-rhn-proxy.xml | 4
web/html/applications/rhn-proxy/5.3/install-rhn-proxy.xml | 4
web/html/applications/rhn-proxy/5.4/install-rhn-proxy.xml | 4
web/modules/rhn/RHN/DB.pm | 35 +++-
web/modules/rhn/RHN/DB/Channel.pm | 7
15 files changed, 72 insertions(+), 112 deletions(-)
---
13 years, 6 months
java/spacewalk-java.spec rel-eng/packages
by Tomas Lestach
java/spacewalk-java.spec | 5 ++++-
rel-eng/packages/spacewalk-java | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
New commits:
commit b169409ebd98b355ff9837664babd758cb96b50e
Author: Tomas Lestach <tlestach(a)redhat.com>
Date: Wed Oct 6 10:36:44 2010 +0200
Automatic commit of package [spacewalk-java] release [1.2.51-1].
diff --git a/java/spacewalk-java.spec b/java/spacewalk-java.spec
index c867b29..745b361 100644
--- a/java/spacewalk-java.spec
+++ b/java/spacewalk-java.spec
@@ -19,7 +19,7 @@ Name: spacewalk-java
Summary: Spacewalk Java site packages
Group: Applications/Internet
License: GPLv2
-Version: 1.2.50
+Version: 1.2.51
Release: 1%{?dist}
URL: https://fedorahosted.org/spacewalk
Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
@@ -340,6 +340,9 @@ fi
%{jardir}/postgresql-jdbc.jar
%changelog
+* Wed Oct 06 2010 Tomas Lestach <tlestach(a)redhat.com> 1.2.51-1
+- 640520 - removing old taskomatic static configuration (tlestach(a)redhat.com)
+
* Tue Oct 05 2010 Jan Pazdziora 1.2.50-1
- Replace Oracle outer join syntax with ANSI syntax for
Channel.findAllBaseChannels and Channel.findByIdAndUserId.
diff --git a/rel-eng/packages/spacewalk-java b/rel-eng/packages/spacewalk-java
index da432c5..4e64be8 100644
--- a/rel-eng/packages/spacewalk-java
+++ b/rel-eng/packages/spacewalk-java
@@ -1 +1 @@
-1.2.50-1 java/
+1.2.51-1 java/
13 years, 6 months
java/conf
by Tomas Lestach
java/conf/default/rhn_taskomatic.conf | 74 ----------------------------------
1 file changed, 74 deletions(-)
New commits:
commit 6113abf8f6eade8f58a14ce87c011c277e005f16
Author: Tomas Lestach <tlestach(a)redhat.com>
Date: Wed Oct 6 10:13:18 2010 +0200
640520 - removing old taskomatic static configuration
diff --git a/java/conf/default/rhn_taskomatic.conf b/java/conf/default/rhn_taskomatic.conf
index fea70a6..bf72b8c 100644
--- a/java/conf/default/rhn_taskomatic.conf
+++ b/java/conf/default/rhn_taskomatic.conf
@@ -2,80 +2,6 @@
# Taskomatic configuration file
###############################################################################
-#------------------------------------------------------------------------------
-# DEFINING TASKS
-#
-# Define tasks as a comma separated list of fully qualified classnames
-# by default we're defining the tasks that are common to both environments
-#
-# NOTE: use the \ character to wrap multiple lines. If not included only
-# the first line is read.
-#------------------------------------------------------------------------------
-
-# default tasks
-taskomatic.default_tasks = com.redhat.rhn.taskomatic.task.DailySummary,\
-com.redhat.rhn.taskomatic.task.ErrataQueue,com.redhat.rhn.taskomatic.task.ErrataMailer,\
-com.redhat.rhn.taskomatic.task.KickstartCleanup,com.redhat.rhn.taskomatic.task.PackageCleanup,\
-com.redhat.rhn.taskomatic.task.SandboxCleanup,com.redhat.rhn.taskomatic.task.SessionCleanup,\
-com.redhat.rhn.taskomatic.task.SummaryPopulation,\
-com.redhat.rhn.taskomatic.task.ErrataCacheTask,\
-com.redhat.rhn.taskomatic.task.CobblerSyncTask,\
-com.redhat.rhn.taskomatic.task.ChannelRepodata,\
-com.redhat.rhn.taskomatic.task.KickstartFileSyncTask,\
-com.redhat.rhn.taskomatic.task.RepoSyncTask,\
-com.redhat.rhn.taskomatic.task.CompareConfigFilesTask
-
-# additional tasks
-taskomatic.tasks =
-
-# satellite only
-# com.redhat.rhn.taskomatic.task.CleanCurrentAlerts,
-# com.redhat.rhn.taskomatic.task.SynchProbeState
-
-#------------------------------------------------------------------------------
-# SCHEDULING
-#
-# To schedule a task define the entry as
-#
-# taskomatic.fully.qualified.task.name.schedule = time
-#
-# where time is when you want the task to run in cron format.
-# You can find more information about the format required at the following url:
-# http://www.opensymphony.com/quartz/wikidocs/CronTriggers%20Tutorial.html
-#------------------------------------------------------------------------------
-
-# Top of every minute
-taskomatic.com.redhat.rhn.taskomatic.task.SynchProbeState.schedule = 0 * * * * ?
-taskomatic.com.redhat.rhn.taskomatic.task.ErrataQueue.schedule = 0 * * * * ?
-taskomatic.com.redhat.rhn.taskomatic.task.CobblerSyncTask.schedule = 0 * * * * ?
-taskomatic.com.redhat.rhn.taskomatic.task.ChannelRepodata.schedule = 0 * * * * ?
-taskomatic.com.redhat.rhn.taskomatic.task.RepoSyncTask.schedule = 0 * * * * ?
-
-# Every 10 minutes
-taskomatic.com.redhat.rhn.taskomatic.task.PackageCleanup.schedule = 0 0/10 * * * ?
-taskomatic.com.redhat.rhn.taskomatic.task.KickstartCleanup.schedule = 0 0/10 * * * ?
-taskomatic.com.redhat.rhn.taskomatic.task.ErrataCacheTask.schedule = 0 0/10 * * * ?
-taskomatic.com.redhat.rhn.taskomatic.task.KickstartFileSyncTask.schedule = 0 0/10 * * * ?
-
-# Every 15 minutes
-taskomatic.com.redhat.rhn.taskomatic.task.SessionCleanup.schedule = 0 0/15 * * * ?
-
-# Every 30 Minutes
-taskomatic.com.redhat.rhn.taskomatic.task.ErrataMailer.schedule = 0 0/30 * * * ?
-
-# Once a day at 4:05:00 AM (beware of 2AM cronjobs)
-taskomatic.com.redhat.rhn.taskomatic.task.SandboxCleanup.schedule = 0 5 4 ? * *
-
-# Once a day at 4:35:00 AM (beware of 2AM cronjobs)
-taskomatic.com.redhat.rhn.taskomatic.task.CleanCurrentAlerts.schedule = 0 35 4 ? * *
-
-# Once a day at 11:00 PM
-taskomatic.com.redhat.rhn.taskomatic.task.SummaryPopulation.schedule = 0 0 23 ? * *
-taskomatic.com.redhat.rhn.taskomatic.task.CompareConfigFilesTask.schedule = 0 0 23 ? * *
-
-# Once a day at 5:00:00 AM
-taskomatic.com.redhat.rhn.taskomatic.task.DailySummary.schedule = 0 0 5 ? * *
-
# configures the number of records processed at any given run.
# A large number could mean a really long execution time
# causing task to misfire. The value is capped at 1000.
13 years, 6 months
web/modules
by Jan Pazdziora
web/modules/rhn/RHN/DB.pm | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
New commits:
commit 507221a13df6862c0b6d306934c9d7a76f58df16
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 10:29:40 2010 +0200
Do not reconnect with every sequence_nextval -- the $self should be usable object to call prepare on.
diff --git a/web/modules/rhn/RHN/DB.pm b/web/modules/rhn/RHN/DB.pm
index 19cef12..9840462 100644
--- a/web/modules/rhn/RHN/DB.pm
+++ b/web/modules/rhn/RHN/DB.pm
@@ -486,8 +486,7 @@ sub sequence_nextval {
my $self = shift;
my $sequence = shift;
- my $dbh = RHN::DB->connect;
- my $sth = $dbh->prepare("SELECT $sequence.nextval FROM DUAL");
+ my $sth = $self->prepare("SELECT $sequence.nextval FROM DUAL");
$sth->execute;
my ($ret) = $sth->fetchrow;
13 years, 6 months
web/modules
by Jan Pazdziora
web/modules/rhn/RHN/DB/Channel.pm | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
New commits:
commit 9dde64d8c3301a671f1026dac890db81a0865520
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 10:24:39 2010 +0200
Use the utility sequence_nextval method instead of direct rhn_channel_id_seq.nextval, to allow portable nextval operation.
diff --git a/web/modules/rhn/RHN/DB/Channel.pm b/web/modules/rhn/RHN/DB/Channel.pm
index 5eb6e32..d1c0c01 100644
--- a/web/modules/rhn/RHN/DB/Channel.pm
+++ b/web/modules/rhn/RHN/DB/Channel.pm
@@ -81,11 +81,8 @@ sub commit {
if ($self->id == -1) {
my $dbh = $transaction || RHN::DB->connect;
- my $sth = $dbh->prepare("SELECT rhn_channel_id_seq.nextval FROM DUAL");
- $sth->execute;
- my ($id) = $sth->fetchrow;
- die "No new channel id from seq rhn_channel_id_seq (possible error: " . $sth->errstr . ")" unless $id;
- $sth->finish;
+ my $id = $dbh->sequence_nextval('rhn_channel_id_seq');
+ die "No new channel id from seq rhn_channel_id_seq" unless $id;
$self->{":modified:"}->{id} = 1;
$self->{__id__} = $id;
13 years, 6 months
web/modules
by Jan Pazdziora
web/modules/rhn/RHN/DB.pm | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
New commits:
commit d515abf797d7983f223125b1bd9fa26e13b0ac1b
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Oct 6 09:59:00 2010 +0200
For PostgreSQL, we just select function(params) instead of begin...end block.
diff --git a/web/modules/rhn/RHN/DB.pm b/web/modules/rhn/RHN/DB.pm
index 6833f2e..19cef12 100644
--- a/web/modules/rhn/RHN/DB.pm
+++ b/web/modules/rhn/RHN/DB.pm
@@ -452,22 +452,34 @@ sub call_function {
my $self = shift;
my $procname = shift;
my @params = @_;
- my @placeholders = map { ":p$_" } 1 .. scalar @params;
+ if ($self->{Driver}->{Name} eq 'Pg') {
+ my $q = "select $procname";
- my $q = "BEGIN\n :ret := $procname";
+ $q .= "(" . join(", ", map { '?' } @params ) . ")";
- $q .= "(" . join(", ", @placeholders) . ");";
- $q .= "\nEND;";
+ my $sth = $self->prepare($q);
+ $sth->execute(@params);
+ my ($ret) = $sth->fetchrow_array();
+ $sth->finish();
- my $ret;
- my $sth = $self->prepare($q);
- $sth->bind_param_inout(":ret" => \$ret, 4096);
+ return $ret;
+ } else {
+ my @placeholders = map { ":p$_" } 1 .. scalar @params;
+ my $q = "BEGIN\n :ret := $procname";
- $sth->bind_param($placeholders[$_ - 1] => $params[$_ - 1]) foreach 1 .. scalar @params;
+ $q .= "(" . join(", ", @placeholders) . ");";
+ $q .= "\nEND;";
- $sth->execute();
+ my $ret;
+ my $sth = $self->prepare($q);
+ $sth->bind_param_inout(":ret" => \$ret, 4096);
- return $ret;
+ $sth->bind_param($placeholders[$_ - 1] => $params[$_ - 1]) foreach 1 .. scalar @params;
+
+ $sth->execute();
+
+ return $ret;
+ }
}
sub sequence_nextval {
13 years, 6 months