Skip to content

Commit

Permalink
Merge pull request #104 from SUSE/smt12_sles15_support
Browse files Browse the repository at this point in the history
SLES15 product tree support
  • Loading branch information
ikapelyukhin authored Nov 22, 2017
2 parents 6387d94 + cec2988 commit 7abdf4a
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME = smt
VERSION = 3.0.30
VERSION = 3.0.31
DESTDIR = /
PERL ?= perl
PERLMODDIR = $(shell $(PERL) -MConfig -e 'print $$Config{installvendorlib};')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alter table ProductExtensions add column ROOTPRODUCTID int not null;
alter table ProductExtensions add column RECOMMENDED bool default false;
alter table ProductExtensions drop index ProductExtensions_pdid_extid_uq;
alter table ProductExtensions drop index ProductExtensions_pdid_extid_src_idx;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
update ProductExtensions set ROOTPRODUCTID = PRODUCTID;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table ProductExtensions ADD UNIQUE KEY `ProductExtensions_pdid_extid_rtpdid_uq` (`PRODUCTID`,`EXTENSIONID`, `ROOTPRODUCTID`);
alter table ProductExtensions ADD KEY `ProductExtensions_pdid_extid_rtpdid_src_idx` (`PRODUCTID`,`EXTENSIONID`,`ROOTPRODUCTID`,`SRC`);
14 changes: 8 additions & 6 deletions db/schemas/mysql/latest/100-smt-tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,14 @@ create table Products (
) ENGINE=InnoDB AUTO_INCREMENT = 100000;


create table ProductExtensions (
PRODUCTID integer NOT NULL,
EXTENSIONID integer NOT NULL,
SRC CHAR(1) DEFAULT 'S',
UNIQUE INDEX ProductExtensions_pdid_extid_uq (PRODUCTID, EXTENSIONID),
INDEX ProductExtensions_pdid_extid_src_idx (PRODUCTID, EXTENSIONID, SRC)
CREATE TABLE `ProductExtensions` (
`PRODUCTID` int(11) NOT NULL,
`EXTENSIONID` int(11) NOT NULL,
`SRC` char(1) DEFAULT 'S',
`ROOTPRODUCTID` int(11) NOT NULL,
`RECOMMENDED` tinyint(1) DEFAULT '0',
UNIQUE KEY `ProductExtensions_pdid_extid_rtpdid_uq` (`PRODUCTID`,`EXTENSIONID`,`ROOTPRODUCTID`),
KEY `ProductExtensions_pdid_extid_rtpdid_src_idx` (`PRODUCTID`,`EXTENSIONID`,`ROOTPRODUCTID`,`SRC`)
) ENGINE=InnoDB;

create table ProductMigrations (
Expand Down
7 changes: 7 additions & 0 deletions package/smt.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Nov 21 13:44:36 UTC 2017 - ikapelyukhin@suse.com

- version 3.0.31
- Add SLE15 product tree support
- Add DB migration to accomodate SLE15 product data from SCC

-------------------------------------------------------------------
Wed Oct 4 07:43:16 UTC 2017 - ikapelyukhin@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/smt.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: smt
Version: 3.0.30
Version: 3.0.31
Release: 0
Summary: Subscription Management Tool
License: GPL-2.0+
Expand Down
2 changes: 1 addition & 1 deletion www/perl-lib/SMT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ use warnings;

use vars qw($SCHEMA_VERSION);

$SCHEMA_VERSION = 3.05;
$SCHEMA_VERSION = 3.06;

1;
5 changes: 0 additions & 5 deletions www/perl-lib/SMT/Rest/SCCAPIv1.pm
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,6 @@ sub products
my @pidarr = keys %{$existingregs};
my $catalogs = SMT::Registration::findCatalogs($self->request(), $self->dbh(), $target, \@pidarr);

if ( (keys %{$catalogs}) == 0)
{
return (Apache2::Const::HTTP_UNPROCESSABLE_ENTITY, "No repositories found");
}

# TODO: get status - from SMT?

# return result
Expand Down
5 changes: 0 additions & 5 deletions www/perl-lib/SMT/Rest/SCCAPIv2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,6 @@ sub products
my @pidarr = keys %{$existingregs};
my $catalogs = SMT::Registration::findCatalogs($self->request(), $self->dbh(), $target, \@pidarr);

if ( (keys %{$catalogs}) == 0)
{
return (Apache2::Const::HTTP_UNPROCESSABLE_ENTITY, "No repositories found");
}

# TODO: get status - from SMT?

#
Expand Down
19 changes: 14 additions & 5 deletions www/perl-lib/SMT/Rest/SCCAPIv3.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ sub get_extensions
p.RELEASE_STAGE release_stage,
1 free,
p.PRODUCT_TYPE product_type,
FALSE recommended,
(CASE WHEN (SELECT c.DOMIRROR
FROM ProductCatalogs pc
JOIN Catalogs c ON pc.CATALOGID = c.ID
Expand Down Expand Up @@ -101,8 +102,9 @@ sub get_extensions
$result->{$pdid}->{id} = int($result->{$pdid}->{id});
$result->{$pdid}->{free} = ($result->{$pdid}->{free} eq "0"?JSON::false:JSON::true);
$result->{$pdid}->{available} = ($result->{$pdid}->{available} eq "0"?JSON::false:JSON::true);
$result->{$pdid}->{recommended} = ($result->{$pdid}->{recommended} eq "0"?JSON::false:JSON::true);
$result->{$pdid}->{repositories} = $self->_repositories_for_product($baseURL, $result->{$pdid}->{id});
foreach my $ext ( values %{$self->_extensions_for_products([$result->{$pdid}->{id}])})
foreach my $ext ( values %{$self->_extensions_for_products([$result->{$pdid}->{id}], $pdid)})
{
push @{$result->{$pdid}->{extensions}}, $ext;
}
Expand Down Expand Up @@ -181,6 +183,7 @@ sub get_subscriptions_products
p.RELEASE_STAGE release_stage,
1 free,
p.PRODUCT_TYPE product_type,
FALSE recommended,
(CASE WHEN (SELECT c.DOMIRROR
FROM ProductCatalogs pc
JOIN Catalogs c ON pc.CATALOGID = c.ID
Expand Down Expand Up @@ -221,8 +224,9 @@ sub get_subscriptions_products
$result->{$pdid}->{id} = int($result->{$pdid}->{id});
$result->{$pdid}->{free} = ($result->{$pdid}->{free} eq "0"?JSON::false:JSON::true);
$result->{$pdid}->{available} = ($result->{$pdid}->{available} eq "0"?JSON::false:JSON::true);
$result->{$pdid}->{recommended} = ($result->{$pdid}->{recommended} eq "0"?JSON::false:JSON::true);
$result->{$pdid}->{repositories} = $self->_repositories_for_product($baseURL, $result->{$pdid}->{id}, 1);
foreach my $ext ( values %{$self->_extensions_for_products([$result->{$pdid}->{id}], 1)})
foreach my $ext ( values %{$self->_extensions_for_products([$result->{$pdid}->{id}], $pdid, 1)})
{
push @{$result->{$pdid}->{extensions}}, $ext;
}
Expand All @@ -246,6 +250,7 @@ sub _extensions_for_products
{
my $self = shift || return {};
my $productids = shift || return {};
my $root_product_id = shift || return {};
my $includeRepoAuth = shift || 0;
my $result = {};

Expand Down Expand Up @@ -275,6 +280,7 @@ sub _extensions_for_products
e.RELEASE_STAGE release_stage,
1 free,
e.PRODUCT_TYPE product_type,
pe.RECOMMENDED recommended,
(CASE WHEN (SELECT c.DOMIRROR
FROM ProductCatalogs pc
JOIN Catalogs c ON pc.CATALOGID = c.ID
Expand All @@ -285,10 +291,10 @@ sub _extensions_for_products
THEN 0 ELSE 1 END ) available
FROM Products p
JOIN ProductExtensions pe ON p.ID = pe.PRODUCTID
JOIN Products e ON pe.EXTENSIONID = e.ID
JOIN Products e ON pe.EXTENSIONID = e.ID AND pe.ROOTPRODUCTID = %s
WHERE p.ID in (%s)
AND e.PRODUCT_LIST = 'Y'
", join(',', @{$productids}));
", $root_product_id, join(',', @{$productids}));
$self->request()->log->info("STATEMENT: $sql");
eval
{
Expand All @@ -302,9 +308,10 @@ sub _extensions_for_products
$result->{$pdid}->{extensions} = [];
$result->{$pdid}->{free} = ($result->{$pdid}->{free} eq "0"?JSON::false:JSON::true);
$result->{$pdid}->{available} = ($result->{$pdid}->{available} eq "0"?JSON::false:JSON::true);
$result->{$pdid}->{recommended} = ($result->{$pdid}->{recommended} eq "0"?JSON::false:JSON::true);
$result->{$pdid}->{id} = int($result->{$pdid}->{id});
$result->{$pdid}->{repositories} = $self->_repositories_for_product($baseURL, $result->{$pdid}->{id}, $includeRepoAuth);
foreach my $ext ( values %{$self->_extensions_for_products([$result->{$pdid}->{id}], $includeRepoAuth)})
foreach my $ext ( values %{$self->_extensions_for_products([$result->{$pdid}->{id}], $root_product_id, $includeRepoAuth)})
{
push @{$result->{$pdid}->{extensions}}, $ext;
}
Expand Down Expand Up @@ -339,6 +346,7 @@ sub _getProduct
p.RELEASE_STAGE release_stage,
1 free,
p.PRODUCT_TYPE product_type,
FALSE recommended,
(CASE WHEN (SELECT c.DOMIRROR
FROM ProductCatalogs pc
JOIN Catalogs c ON pc.CATALOGID = c.ID
Expand Down Expand Up @@ -366,6 +374,7 @@ sub _getProduct
{
$product->{free} = ($product->{free} eq "0"?JSON::false:JSON::true);
$product->{available} = ($product->{available} eq "0"?JSON::false:JSON::true);
$product->{recommended} = ($product->{recommended} eq "0"?JSON::false:JSON::true);
$product->{id} = int($product->{id});
$product->{repositories} = $self->_repositories_for_product($baseURL, $product->{id});
$result = $product;
Expand Down
5 changes: 0 additions & 5 deletions www/perl-lib/SMT/Rest/SCCAPIv4.pm
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,6 @@ sub delete_single_product
my @pidarr = keys %{$existingregs};
my $catalogs = SMT::Registration::findCatalogs($self->request(), $self->dbh(), $target, \@pidarr);

if ( (keys %{$catalogs}) == 0)
{
return (Apache2::Const::HTTP_UNPROCESSABLE_ENTITY, "No repositories found");
}

foreach my $param ( qw{identifier version arch} ) {
unless ( exists $c->{$param} && $c->{$param} ) {
return (Apache2::Const::HTTP_UNPROCESSABLE_ENTITY, "Missing required parameter: $param");
Expand Down
66 changes: 49 additions & 17 deletions www/perl-lib/SMT/SCCSync.pm
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ sub _updateProducts
{
my $self = shift;
my $product = shift;
my $root_product_id = shift;

my $statement = "";
my $ret = 0;
Expand Down Expand Up @@ -735,6 +736,14 @@ id="\${mirror:id}" description="\${mirror:name}" type="\${mirror:type}">
EOS
;

$root_product_id = $product->{id} if ($product->{product_type} eq 'base');

foreach my $ext (@{$product->{extensions}})
{
$ret += $self->_updateProducts($ext, $root_product_id);
$self->_collectExtensions($product->{id}, $ext->{id}, $root_product_id, $ext->{recommended});
}

# we inserted/update this product already in this run
# so let's skip it
return 0 if(exists $self->{PROD_DONE}->{$product->{id}});
Expand Down Expand Up @@ -913,11 +922,6 @@ EOS
}
$ret += $retprd;

foreach my $ext (@{$product->{extensions}})
{
$ret += $self->_updateProducts($ext);
$self->_collectExtensions($product->{id}, $ext->{id});
}
if (exists $product->{predecessor_ids})
{
$self->_collectMigrations($product->{id}, $product->{predecessor_ids});
Expand Down Expand Up @@ -990,8 +994,15 @@ sub _collectExtensions
my $self = shift || return;
my $prdid = shift || return;
my $extid = shift || return;

$self->{EXTS}->{"$prdid-$extid"} = {productid => $prdid, extensionid => $extid};
my $root_product_id = shift || return;
my $recommended = shift;

$self->{EXTS}->{"$prdid-$extid-$root_product_id"} = {
productid => $prdid,
extensionid => $extid,
root_product_id => $root_product_id,
recommended => $recommended
};
}

sub _updateExtensions
Expand All @@ -1000,14 +1011,14 @@ sub _updateExtensions
my $err = 0;
my $href = {};

my $sql = "select PRODUCTID, EXTENSIONID from ProductExtensions where SRC = 'S'";
my $sql = "select PRODUCTID, EXTENSIONID, ROOTPRODUCTID, RECOMMENDED from ProductExtensions where SRC = 'S'";
printLog($self->{LOG}, $self->vblevel(), LOG_DEBUG, "STATEMENT: $sql");
eval {
my $ref = $self->{DBH}->selectall_arrayref($sql, {Slice => {}});

foreach my $v (@{$ref})
{
$href->{$v->{PRODUCTID}."-".$v->{EXTENSIONID}} = $v;
$href->{$v->{PRODUCTID}."-".$v->{EXTENSIONID}."-".$v->{ROOTPRODUCTID}} = $v;
}
};
if($@)
Expand All @@ -1022,10 +1033,15 @@ sub _updateExtensions
$self->{LOG}, $self->vblevel());
my $extid = SMT::Utils::lookupProductIdByDataId($self->{DBH}, $self->{EXTS}->{$key}->{extensionid}, 'S',
$self->{LOG}, $self->vblevel());
my $root_product_id = SMT::Utils::lookupProductIdByDataId($self->{DBH}, $self->{EXTS}->{$key}->{root_product_id}, 'S',
$self->{LOG}, $self->vblevel());

my $recommended = $self->{EXTS}->{$key}->{recommended};

if (exists $href->{$prdid."-".$extid})
my $hash_key = $prdid."-".$extid."-".$root_product_id;
if (exists $href->{$hash_key} && $href->{$hash_key}->{RECOMMENDED} == $recommended)
{
delete $href->{$prdid."-".$extid};
delete $href->{$hash_key};
next;
}
else
Expand All @@ -1042,9 +1058,22 @@ sub _updateExtensions
$err += 1;
next;
}
my $sql = sprintf("INSERT INTO ProductExtensions VALUES ( %s, %s, 'S')",
$self->{DBH}->quote($prdid),
$self->{DBH}->quote($extid));
if(!$root_product_id)
{
printLog($self->{LOG}, $self->vblevel(), LOG_ERROR, "Root product not found for: ".$self->{EXTS}->{$key}->{root_product_id});
$err += 1;
next;
}
my $sql = sprintf(
"INSERT INTO ProductExtensions (PRODUCTID, EXTENSIONID, ROOTPRODUCTID, RECOMMENDED, SRC)
VALUES ( %s, %s, %s, %s, 'S')
ON DUPLICATE KEY UPDATE recommended = %s",
$self->{DBH}->quote($prdid),
$self->{DBH}->quote($extid),
$self->{DBH}->quote($root_product_id),
$self->{DBH}->quote($recommended),
$self->{DBH}->quote($recommended) # on duplicate key
);
printLog($self->{LOG}, $self->vblevel(), LOG_DEBUG, "STATEMENT: $sql");
eval {
$self->{DBH}->do($sql);
Expand All @@ -1054,14 +1083,17 @@ sub _updateExtensions
printLog($self->{LOG}, $self->vblevel(), LOG_ERROR, "$@");
return 1;
}
delete $href->{$hash_key};
}
}
# remove obsolete entries
foreach my $key (keys %{$href})
{
$sql = sprintf("DELETE FROM ProductExtensions WHERE PRODUCTID = %s AND EXTENSIONID = %s",
$self->{DBH}->quote($href->{$key}->{PRODUCTID}),
$self->{DBH}->quote($href->{$key}->{EXTENSIONID}));
$sql = sprintf("DELETE FROM ProductExtensions WHERE PRODUCTID = %s AND EXTENSIONID = %s AND ROOTPRODUCTID = %s",
$self->{DBH}->quote($href->{$key}->{PRODUCTID}),
$self->{DBH}->quote($href->{$key}->{EXTENSIONID}),
$self->{DBH}->quote($href->{$key}->{ROOTPRODUCTID})
);
printLog($self->{LOG}, $self->vblevel(), LOG_DEBUG, "STATEMENT: $sql");
eval {
$self->{DBH}->do($sql);
Expand Down

0 comments on commit 7abdf4a

Please sign in to comment.