modules/core/dbutils/pom.xml
| 2
modules/core/dbutils/src/main/scripts/dbsetup/content-schema.xml
| 12
modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
| 33 +
modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSource.java
| 33 -
modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceSyncResults.java
| 8
modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceSyncStatus.java
| 27 -
modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSyncStatus.java
| 27 +
modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
| 57 +++
modules/core/domain/src/main/java/org/rhq/core/domain/content/RepoSyncResults.java
| 168 ++++++++++
modules/core/domain/src/test/java/org/rhq/core/domain/content/test/ContentSourceSyncResultsTest.java
| 6
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java
| 6
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
| 35 --
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java
| 84 +----
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/ContentProviderSyncJob.java
| 5
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java
| 4
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java
| 38 --
16 files changed, 367 insertions(+), 178 deletions(-)
New commits:
commit 08a2b166ec8994e6419728d58c8e1bab9c28530b
Author: Mike McCune <mmccune(a)gibson.pdx.redhat.com>
Date: Tue Nov 24 10:46:47 2009 -0800
1102 - adding RepoSyncResults
diff --git a/modules/core/dbutils/pom.xml b/modules/core/dbutils/pom.xml
index f352799..b375393 100644
--- a/modules/core/dbutils/pom.xml
+++ b/modules/core/dbutils/pom.xml
@@ -22,7 +22,7 @@
<properties>
<scm.module.path>modules/core/dbutils/</scm.module.path>
- <db.schema.version>2.71</db.schema.version>
+ <db.schema.version>2.72</db.schema.version>
</properties>
<dependencies>
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/content-schema.xml
b/modules/core/dbutils/src/main/scripts/dbsetup/content-schema.xml
index 8e6e627..ad47c4a 100644
--- a/modules/core/dbutils/src/main/scripts/dbsetup/content-schema.xml
+++ b/modules/core/dbutils/src/main/scripts/dbsetup/content-schema.xml
@@ -208,9 +208,19 @@
<column name="START_TIME" type="LONG"
required="true"/>
<column name="END_TIME" type="LONG"
required="false"/>
<column name="RESULTS" type="LONGVARCHAR"
required="false"/>
-
<column name="CONTENT_SRC_ID" type="INTEGER"
required="true" references="RHQ_CONTENT_SOURCE"/>
</table>
+
+ <table name="RHQ_REPO_SYNC">
+ <column name="ID" default="sequence-only"
initial="10001" primarykey="true" required="true"
type="INTEGER"/>
+ <column name="STATUS" type="VARCHAR2" size="16"
required="true"/>
+ <column name="START_TIME" type="LONG"
required="true"/>
+ <column name="END_TIME" type="LONG"
required="false"/>
+ <column name="RESULTS" type="LONGVARCHAR"
required="false"/>
+ <column name="PERCENT_COMPLETE" type="LONGVARCHAR"
required="false"/>
+ <column name="REPO_ID" type="INTEGER"
required="true" references="RHQ_REPO"/>
+ </table>
+
<table name="RHQ_PACKAGE_INST_STEP">
<column name="ID" default="sequence-only"
initial="10001" primarykey="true" required="true"
type="INTEGER"/>
diff --git a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
index eaeef31..a863d45 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -2637,9 +2637,36 @@
REFERENCES RHQ_REPO ( ID )
</statement>
</schema-directSQL>
-
</schemaSpec>
-
- </dbupgrade>
+
+ <!-- Adding repo_sync support -->
+ <schemaSpec version="2.72">
+ <schema-createSequence name="RHQ_REPO_SYNC_ID_SEQ"
initial="10001" />
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_REPO_SYNC ( ID INTEGER PRIMARY KEY )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_REPO_SYNC" column="ID"
nullable="false" />
+ <schema-addColumn table="RHQ_REPO_SYNC" column="STATUS"
precision="16" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_REPO_SYNC" column="STATUS"
nullable="false" />
+ <schema-addColumn table="RHQ_REPO_SYNC"
column="START_TIME" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_REPO_SYNC"
column="START_TIME" nullable="false" />
+ <schema-addColumn table="RHQ_REPO_SYNC"
column="END_TIME" columnType="INTEGER" />
+ <schema-addColumn table="RHQ_REPO_SYNC"
column="RESULTS" columnType="LONGVARCHAR" />
+ <schema-addColumn table="RHQ_REPO_SYNC"
column="PERCENT_COMPLETE" columnType="LONG" />
+ <schema-addColumn table="RHQ_REPO_SYNC"
column="REPO_ID" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_REPO_SYNC"
column="REPO_ID" nullable="false" />
+ <schema-directSQL>
+ <statement desc="Creating RHQ_REPO_SYNC foreign key relation to
RHQ_REPO for scheduled jobs">
+ ALTER TABLE RHQ_REPO_SYNC
+ ADD CONSTRAINT RHQ_REPO_SYNC_REPO_ID_FKEY
+ FOREIGN KEY (REPO_ID)
+ REFERENCES RHQ_REPO (ID)
+ </statement>
+ </schema-directSQL>
+ </schemaSpec>
+
+ </dbupgrade>
</target>
</project>
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSource.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSource.java
index 80cedf7..511da1a 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSource.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSource.java
@@ -24,9 +24,6 @@ package org.rhq.core.domain.content;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -141,7 +138,7 @@ public class ContentSource implements Serializable {
@OneToMany(mappedBy = "contentSource", fetch = FetchType.LAZY, cascade =
CascadeType.REMOVE)
private Set<RepoContentSource> repoContentSources;
- // Constructor
+ // Constructor asdf
public ContentSource() {
// for JPA use
@@ -294,35 +291,9 @@ public class ContentSource implements Serializable {
}
/**
- * The list of sync results; ordered with the latest results first in the list
guaranteed.
- * guaranteed.
+ * The list of sync results - order not ensured
*/
public List<ContentSourceSyncResults> getSyncResults() {
-
- Comparator dc = new Comparator() {
- public int compare(Object arg0, Object arg1) {
- long currTime = System.currentTimeMillis();
- ContentSourceSyncResults c1 = (ContentSourceSyncResults) arg0;
- ContentSourceSyncResults c2 = (ContentSourceSyncResults) arg1;
- Date d1 = null;
- Date d2 = null;
-
- if (c1.getEndTime() == null) {
- d1 = new Date(currTime);
- } else {
- d1 = new Date(c1.getEndTime());
- }
- if (c2.getEndTime() == null) {
- d2 = new Date(currTime);
- } else {
- d2 = new Date(c2.getEndTime());
- }
- return d1.compareTo(d2);
- }
- };
-
- Collections.sort(syncResults, dc);
-
return syncResults;
}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceSyncResults.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceSyncResults.java
index 25ce4f5..87fb2d3 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceSyncResults.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceSyncResults.java
@@ -72,7 +72,7 @@ public class ContentSourceSyncResults implements Serializable {
@Column(name = "STATUS", nullable = false)
@Enumerated(EnumType.STRING)
- private ContentSourceSyncStatus status;
+ private ContentSyncStatus status;
@Column(name = "START_TIME", nullable = false)
private long startTime;
@@ -85,7 +85,7 @@ public class ContentSourceSyncResults implements Serializable {
protected ContentSourceSyncResults() {
this.startTime = System.currentTimeMillis();
- this.status = ContentSourceSyncStatus.INPROGRESS;
+ this.status = ContentSyncStatus.INPROGRESS;
}
public ContentSourceSyncResults(ContentSource contentSource) {
@@ -115,11 +115,11 @@ public class ContentSourceSyncResults implements Serializable {
/**
* The status that typically indicates if the sync request succeeded, failed or is
currently in progress.
*/
- public ContentSourceSyncStatus getStatus() {
+ public ContentSyncStatus getStatus() {
return status;
}
- public void setStatus(ContentSourceSyncStatus status) {
+ public void setStatus(ContentSyncStatus status) {
this.status = status;
}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceSyncStatus.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceSyncStatus.java
deleted file mode 100644
index e304a41..0000000
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceSyncStatus.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.rhq.core.domain.content;
-
-public enum ContentSourceSyncStatus {
- INPROGRESS, SUCCESS, FAILURE, NONE
-}
\ No newline at end of file
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSyncStatus.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSyncStatus.java
new file mode 100644
index 0000000..799640d
--- /dev/null
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSyncStatus.java
@@ -0,0 +1,27 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.rhq.core.domain.content;
+
+public enum ContentSyncStatus {
+ INPROGRESS, SUCCESS, FAILURE, NONE
+}
\ No newline at end of file
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
index 2d1d0aa..efcaa0c 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
@@ -23,7 +23,12 @@
package org.rhq.core.domain.content;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
@@ -36,6 +41,7 @@ import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
+import javax.persistence.OrderBy;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.SequenceGenerator;
@@ -93,8 +99,7 @@ import org.rhq.core.domain.resource.Resource;
+ " WHERE rcs.repo.id = r.id " //
+ " AND rcs.contentSource.id = :contentSourceId) = 1 " //
+ "AND (SELECT COUNT(rcs) FROM RepoContentSource rcs" //
- + " WHERE rcs.repo.id = r.id) = 1 ")
- })
+ + " WHERE rcs.repo.id = r.id) = 1 ") })
@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_REPO_ID_SEQ")
@Table(name = "RHQ_REPO")
public class Repo implements Serializable, Taggable {
@@ -157,6 +162,11 @@ public class Repo implements Serializable, Taggable {
@OneToMany(mappedBy = "repo", fetch = FetchType.LAZY)
private Set<RepoTag> repoTags;
+ @OneToMany(mappedBy = "repo", fetch = FetchType.LAZY, cascade =
CascadeType.REMOVE)
+ @OrderBy("startTime DESC")
+ // latest appears first, oldest last
+ private List<RepoSyncResults> syncResults;
+
@Transient
private String syncStatus;
@@ -337,6 +347,7 @@ public class Repo implements Serializable, Taggable {
*/
@Transient
public String getSyncStatus() {
+
return this.syncStatus;
}
@@ -791,4 +802,46 @@ public class Repo implements Serializable, Taggable {
public void setSyncStatus(String syncStatusIn) {
this.syncStatus = syncStatusIn;
}
+
+ public void addSyncResult(RepoSyncResults syncResult) {
+ if (this.syncResults == null) {
+ this.syncResults = new ArrayList<RepoSyncResults>();
+ }
+
+ this.syncResults.add(syncResult);
+ syncResult.setRepo(this);
+ }
+
+ /**
+ * The list of sync results - order ENSURED by date sort on start and end times
+ */
+ public List<RepoSyncResults> getSyncResults() {
+
+ Comparator dc = new Comparator() {
+ public int compare(Object arg0, Object arg1) {
+ long currTime = System.currentTimeMillis();
+ ContentSourceSyncResults c1 = (ContentSourceSyncResults) arg0;
+ ContentSourceSyncResults c2 = (ContentSourceSyncResults) arg1;
+ Date d1 = null;
+ Date d2 = null;
+
+ if (c1.getEndTime() == null) {
+ d1 = new Date(currTime);
+ } else {
+ d1 = new Date(c1.getEndTime());
+ }
+ if (c2.getEndTime() == null) {
+ d2 = new Date(currTime);
+ } else {
+ d2 = new Date(c2.getEndTime());
+ }
+ return d1.compareTo(d2);
+ }
+ };
+
+ Collections.sort(syncResults, dc);
+
+ return syncResults;
+ }
+
}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/content/RepoSyncResults.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/content/RepoSyncResults.java
new file mode 100644
index 0000000..a6c0050
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/RepoSyncResults.java
@@ -0,0 +1,168 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.rhq.core.domain.content;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+/**
+ * Represents the results of a repo sync request. When a {@link Repo} synchronizes with
its remote
+ * backend, the results of that are stored in this object.
+ *
+ */
+@Entity
+@NamedQueries( {
+ @NamedQuery(name = RepoSyncResults.QUERY_GET_INPROGRESS_BY_REPO_ID, query =
"SELECT rssr "
+ + " FROM RepoSyncResults rssr " + " WHERE rssr.repo.id = :repoId
" + " AND status = 'INPROGRESS' "
+ + " ORDER BY rssr.startTime DESC "),
+ @NamedQuery(name = RepoSyncResults.QUERY_GET_ALL_BY_REPO_ID, query = "SELECT
rssr "
+ + " FROM RepoSyncResults rssr " + " WHERE rssr.repo.id = :repoId
") })
+@SequenceGenerator(name = "SEQ", sequenceName =
"RHQ_REPO_SYNC_ID_SEQ")
+@Table(name = "RHQ_REPO_SYNC")
+public class RepoSyncResults implements Serializable {
+ public static final String QUERY_GET_INPROGRESS_BY_REPO_ID =
"RepoSyncResults.getInProgressByRepoId";
+ public static final String QUERY_GET_ALL_BY_REPO_ID =
"RepoSyncResults.getAllByRepoId";
+
+ private static final long serialVersionUID = 1L;
+
+ @Column(name = "ID", nullable = false)
+ @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ")
+ @Id
+ private int id;
+
+ @JoinColumn(name = "REPO_ID", referencedColumnName = "ID",
nullable = false)
+ @ManyToOne(fetch = FetchType.LAZY)
+ private Repo repo;
+
+ @Column(name = "STATUS", nullable = false)
+ @Enumerated(EnumType.STRING)
+ private ContentSyncStatus status;
+
+ @Column(name = "START_TIME", nullable = false)
+ private long startTime;
+
+ @Column(name = "END_TIME", nullable = true)
+ private Long endTime;
+
+ @Column(name = "RESULTS", nullable = true)
+ private String results;
+
+ protected RepoSyncResults() {
+ this.startTime = System.currentTimeMillis();
+ this.status = ContentSyncStatus.INPROGRESS;
+ }
+
+ public RepoSyncResults(Repo repoIn) {
+ this();
+ this.repo = repoIn;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ /**
+ * The Repo that performed the sync.
+ */
+ public Repo getRepo() {
+ return repo;
+ }
+
+ public void setRepo(Repo repoIn) {
+ this.repo = repoIn;
+ }
+
+ /**
+ * The status that typically indicates if the sync request succeeded, failed or is
currently in progress.
+ */
+ public ContentSyncStatus getStatus() {
+ return status;
+ }
+
+ public void setStatus(ContentSyncStatus status) {
+ this.status = status;
+ }
+
+ /**
+ * Indicates when the sync began.
+ */
+ public long getStartTime() {
+ return startTime;
+ }
+
+ public void setStartTime(long startTime) {
+ this.startTime = startTime;
+ }
+
+ /**
+ * Indicates when the sync stopped.
+ */
+ public Long getEndTime() {
+ return endTime;
+ }
+
+ public void setEndTime(Long endTime) {
+ this.endTime = endTime;
+ }
+
+ /**
+ * Tells you the results of the sync.
+ */
+ public String getResults() {
+ return results;
+ }
+
+ public void setResults(String results) {
+ this.results = results;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder str = new StringBuilder(this.getClass().getSimpleName() + ":
");
+ str.append("start-time=[" + new Date(startTime));
+ str.append("], end-time=[" + ((endTime != null) ? new Date(endTime) :
"---"));
+ str.append("], status=[" + status);
+ str.append("], repo=[" + repo);
+ str.append("]");
+ return str.toString();
+ }
+}
\ No newline at end of file
diff --git
a/modules/core/domain/src/test/java/org/rhq/core/domain/content/test/ContentSourceSyncResultsTest.java
b/modules/core/domain/src/test/java/org/rhq/core/domain/content/test/ContentSourceSyncResultsTest.java
index 156bfa2..eed6b3f 100644
---
a/modules/core/domain/src/test/java/org/rhq/core/domain/content/test/ContentSourceSyncResultsTest.java
+++
b/modules/core/domain/src/test/java/org/rhq/core/domain/content/test/ContentSourceSyncResultsTest.java
@@ -31,7 +31,7 @@ import org.testng.annotations.Test;
import org.rhq.core.domain.content.Architecture;
import org.rhq.core.domain.content.ContentSource;
import org.rhq.core.domain.content.ContentSourceSyncResults;
-import org.rhq.core.domain.content.ContentSourceSyncStatus;
+import org.rhq.core.domain.content.ContentSyncStatus;
import org.rhq.core.domain.content.ContentSourceType;
import org.rhq.core.domain.content.Package;
import org.rhq.core.domain.content.PackageType;
@@ -83,13 +83,13 @@ public class ContentSourceSyncResultsTest extends AbstractEJB3Test {
assert syncResults.size() == 1;
results = syncResults.get(0);
assert results.getContentSource().equals(cs);
- assert results.getStatus() == ContentSourceSyncStatus.INPROGRESS;
+ assert results.getStatus() == ContentSyncStatus.INPROGRESS;
assert results.getResults() == null;
assert results.getEndTime() == null;
assert results.getStartTime() <= System.currentTimeMillis();
results.setEndTime(System.currentTimeMillis());
- results.setStatus(ContentSourceSyncStatus.FAILURE);
+ results.setStatus(ContentSyncStatus.FAILURE);
results.setResults("dummy failure");
results = em.merge(results);
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java
index 1365208..40bc541 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java
@@ -59,7 +59,7 @@ import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.content.Architecture;
import org.rhq.core.domain.content.ContentSource;
import org.rhq.core.domain.content.ContentSourceSyncResults;
-import org.rhq.core.domain.content.ContentSourceSyncStatus;
+import org.rhq.core.domain.content.ContentSyncStatus;
import org.rhq.core.domain.content.ContentSourceType;
import org.rhq.core.domain.content.Distribution;
import org.rhq.core.domain.content.DistributionFile;
@@ -893,7 +893,7 @@ public class ContentSourceManagerBean implements
ContentSourceManagerLocal {
// happened that left them in a bad state which will most likely never change
unless we do it here.
// If a content source sync takes longer than 24 hours, then we've made a
bad assumption here and
// this code needs to change - though I doubt any content source will take 24
hours to sync.
- if (results.getStatus() == ContentSourceSyncStatus.INPROGRESS) {
+ if (results.getStatus() == ContentSyncStatus.INPROGRESS) {
if ((System.currentTimeMillis() - inprogressList.get(0).getStartTime())
< (1000 * 60 * 60 * 24)) {
alreadyInProgress = true;
inprogressList.remove(0); // we need to leave this one as-is, so get
rid of it from list
@@ -902,7 +902,7 @@ public class ContentSourceManagerBean implements
ContentSourceManagerLocal {
// take this time to mark all old inprogress results as failed
for (ContentSourceSyncResults inprogress : inprogressList) {
- inprogress.setStatus(ContentSourceSyncStatus.FAILURE);
+ inprogress.setStatus(ContentSyncStatus.FAILURE);
inprogress.setEndTime(System.currentTimeMillis());
inprogress.setResults("This synchronization seems to have stalled or
ended abnormally.");
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
index 4f9ec58..b34c324 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
@@ -40,8 +40,7 @@ import org.jboss.annotation.IgnoreDependency;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.content.ContentSource;
-import org.rhq.core.domain.content.ContentSourceSyncResults;
-import org.rhq.core.domain.content.ContentSourceSyncStatus;
+import org.rhq.core.domain.content.ContentSyncStatus;
import org.rhq.core.domain.content.Distribution;
import org.rhq.core.domain.content.PackageVersion;
import org.rhq.core.domain.content.PackageVersionContentSource;
@@ -54,6 +53,7 @@ import org.rhq.core.domain.content.RepoPackageVersion;
import org.rhq.core.domain.content.RepoRelationship;
import org.rhq.core.domain.content.RepoRelationshipType;
import org.rhq.core.domain.content.RepoRepoRelationship;
+import org.rhq.core.domain.content.RepoSyncResults;
import org.rhq.core.domain.content.ResourceRepo;
import org.rhq.core.domain.content.composite.RepoComposite;
import org.rhq.core.domain.criteria.PackageVersionCriteria;
@@ -892,27 +892,22 @@ public class RepoManagerBean implements RepoManagerLocal,
RepoManagerRemote {
public String calculateSyncStatus(Subject subject, int repoId) {
Repo found = this.getRepo(subject, repoId);
- Set<ContentSourceSyncStatus> stati = new
HashSet<ContentSourceSyncStatus>();
- Set<ContentSource> contentSources = found.getContentSources();
- Iterator<ContentSource> i = contentSources.iterator();
- while (i.hasNext()) {
- ContentSource cs = i.next();
- List<ContentSourceSyncResults> syncResults = cs.getSyncResults();
- // Add the most recent sync results status
- if (syncResults != null && (!syncResults.isEmpty()) &&
syncResults.get(0) != null) {
- stati.add(syncResults.get(0).getStatus());
- } else {
- stati.add(ContentSourceSyncStatus.NONE);
- }
+ Set<ContentSyncStatus> stati = new HashSet<ContentSyncStatus>();
+ List<RepoSyncResults> syncResults = found.getSyncResults();
+ // Add the most recent sync results status
+ if (syncResults != null && (!syncResults.isEmpty()) &&
syncResults.get(0) != null) {
+ stati.add(syncResults.get(0).getStatus());
+ } else {
+ stati.add(ContentSyncStatus.NONE);
}
- if (stati.contains(ContentSourceSyncStatus.FAILURE)) {
- return ContentSourceSyncStatus.FAILURE.toString();
+ if (stati.contains(ContentSyncStatus.FAILURE)) {
+ return ContentSyncStatus.FAILURE.toString();
}
- if (stati.contains(ContentSourceSyncStatus.INPROGRESS)) {
- return ContentSourceSyncStatus.INPROGRESS.toString();
+ if (stati.contains(ContentSyncStatus.INPROGRESS)) {
+ return ContentSyncStatus.INPROGRESS.toString();
}
- if (stati.contains(ContentSourceSyncStatus.SUCCESS)) {
- return ContentSourceSyncStatus.SUCCESS.toString();
+ if (stati.contains(ContentSyncStatus.SUCCESS)) {
+ return ContentSyncStatus.SUCCESS.toString();
}
return null;
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java
index 6bb8b41..1e195fb 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java
@@ -38,8 +38,8 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.content.ContentSource;
import org.rhq.core.domain.content.ContentSourceSyncResults;
-import org.rhq.core.domain.content.ContentSourceSyncStatus;
import org.rhq.core.domain.content.ContentSourceType;
+import org.rhq.core.domain.content.ContentSyncStatus;
import org.rhq.core.domain.content.Repo;
import org.rhq.core.domain.util.PageControl;
import org.rhq.enterprise.server.auth.SubjectManagerLocal;
@@ -93,7 +93,6 @@ public class ContentProviderManager {
return inputStream;
}
-
/**
* Asks that the adapter responsible for the given content source return a stream to
the
* DistributionFile bits for the DistributionFile at the given location.
@@ -103,8 +102,7 @@ public class ContentProviderManager {
* @return the stream to the DistributionFile bits
* @throws Exception if the adapter failed to load the bits
*/
- public InputStream loadDistributionFileBits(int contentSourceId, String location)
- throws Exception {
+ public InputStream loadDistributionFileBits(int contentSourceId, String location)
throws Exception {
ContentProvider adapter = getIsolatedContentProvider(contentSourceId);
DistributionSource distSource = (DistributionSource) adapter;
@@ -112,8 +110,7 @@ public class ContentProviderManager {
if (inputStream == null) {
throw new Exception("Adapter for content source [" +
contentSourceId
- + "] failed to give us a stream to the distribution file at location
[" + location +
- "]");
+ + "] failed to give us a stream to the distribution file at location
[" + location + "]");
}
return inputStream;
@@ -145,11 +142,9 @@ public class ContentProviderManager {
StringBuilder progress = new StringBuilder();
try {
- ContentSource contentSource = contentSourceManager
- .getContentSource(overlord, contentSourceId);
+ ContentSource contentSource = contentSourceManager.getContentSource(overlord,
contentSourceId);
if (contentSource == null) {
- throw new Exception(
- "Cannot sync a non-existing content source [" +
contentSourceId + "]");
+ throw new Exception("Cannot sync a non-existing content source
[" + contentSourceId + "]");
}
// This should not take very long so it should be OK to block other callers.
@@ -159,8 +154,7 @@ public class ContentProviderManager {
// We can come back and revisit if we need more fine-grained locking.
synchronized (synchronizeContentSourceLock) {
progress.append(new Date()).append(": ");
- progress.append("Start synchronization of content provider [")
- .append(contentSource.getName()).append(
+ progress.append("Start synchronization of content provider
[").append(contentSource.getName()).append(
"]");
progress.append('\n');
progress.append(new Date()).append(": ");
@@ -182,16 +176,14 @@ public class ContentProviderManager {
return false;
}
- RepoSourceSynchronizer repoSourceSynchronizer =
- new RepoSourceSynchronizer(contentSource, provider);
+ RepoSourceSynchronizer repoSourceSynchronizer = new
RepoSourceSynchronizer(contentSource, provider);
repoSourceSynchronizer.synchronizeCandidateRepos(progress);
- }
- catch (Throwable t) {
+ } catch (Throwable t) {
if (results != null) {
// try to reload the results in case it was updated by the SLSB before
the
// exception happened
- ContentSourceSyncResults reloadedResults = contentSourceManager
- .getContentSourceSyncResults(results.getId());
+ ContentSourceSyncResults reloadedResults =
contentSourceManager.getContentSourceSyncResults(results
+ .getId());
if (reloadedResults != null) {
results = reloadedResults;
if (results.getResults() != null) {
@@ -205,7 +197,7 @@ public class ContentProviderManager {
progress.append("SYNCHRONIZATION ERROR - STACK TRACE
FOLLOWS:\n");
progress.append(baos.toString());
results.setResults(progress.toString());
- results.setStatus(ContentSourceSyncStatus.FAILURE);
+ results.setStatus(ContentSyncStatus.FAILURE);
// finally clause will merge this
}
@@ -254,13 +246,12 @@ public class ContentProviderManager {
for (ContentSource source : repo.getContentSources()) {
ContentProvider provider = getIsolatedContentProvider(source.getId());
- PackageSourceSynchronizer packageSourceSynchronizer =
- new PackageSourceSynchronizer(repo, source, provider);
+ PackageSourceSynchronizer packageSourceSynchronizer = new
PackageSourceSynchronizer(repo, source, provider);
packageSourceSynchronizer.synchronizePackageMetadata();
packageSourceSynchronizer.synchronizePackageBits();
- DistributionSourceSynchronizer distributionSourceSynchronizer =
- new DistributionSourceSynchronizer(repo, source, provider);
+ DistributionSourceSynchronizer distributionSourceSynchronizer = new
DistributionSourceSynchronizer(repo,
+ source, provider);
distributionSourceSynchronizer.synchronizeDistributionMetadata();
distributionSourceSynchronizer.synchronizeDistributionBits();
}
@@ -281,8 +272,7 @@ public class ContentProviderManager {
try {
adapter.testConnection();
- }
- catch (Throwable t) {
+ } catch (Throwable t) {
return false;
}
@@ -326,11 +316,8 @@ public class ContentProviderManager {
ContentProvider adapter = getIsolatedContentSourceAdapter(contentSource);
adapter.initialize(contentSource.getConfiguration());
- }
- catch (Exception e) {
- log.warn(
- "Failed to initialize adapter for content source [" +
contentSource.getName() + "]",
- e);
+ } catch (Exception e) {
+ log.warn("Failed to initialize adapter for content source [" +
contentSource.getName() + "]", e);
throw new InitializationException(e);
}
}
@@ -358,10 +345,8 @@ public class ContentProviderManager {
ContentProvider adapter = getIsolatedContentSourceAdapter(contentSource);
adapter.shutdown();
- }
- catch (Throwable t) {
- log.warn(
- "Failed to shutdown adapter for content source [" +
contentSource.getName() + "]", t);
+ } catch (Throwable t) {
+ log.warn("Failed to shutdown adapter for content source [" +
contentSource.getName() + "]", t);
} finally {
this.adapters.remove(contentSource);
}
@@ -398,8 +383,7 @@ public class ContentProviderManager {
}
}
- throw new RuntimeException(
- "Content source ID [" + contentProviderId + "] doesn't
exist; can't get adapter");
+ throw new RuntimeException("Content source ID [" + contentProviderId +
"] doesn't exist; can't get adapter");
}
/**
@@ -414,14 +398,12 @@ public class ContentProviderManager {
protected void initialize(ContentServerPluginManager pluginManager) {
this.pluginManager = pluginManager;
- ContentSourceMetadataManagerLocal metadataManager = LookupUtil
- .getContentSourceMetadataManager();
+ ContentSourceMetadataManagerLocal metadataManager =
LookupUtil.getContentSourceMetadataManager();
ContentSourceManagerLocal contentSourceManager =
LookupUtil.getContentSourceManager();
// Our plugin manager should have parsed all descriptors and have our types for
us.
// Let's register the types to make sure they are merged with the old
existing types.
- ContentSourcePluginMetadataManager pluginMetadataManager = this.pluginManager
- .getMetadataManager();
+ ContentSourcePluginMetadataManager pluginMetadataManager =
this.pluginManager.getMetadataManager();
Set<ContentSourceType> allTypes =
pluginMetadataManager.getAllContentSourceTypes();
metadataManager.registerTypes(allTypes);
@@ -437,8 +419,7 @@ public class ContentProviderManager {
for (ContentSource contentSource : contentSources) {
try {
startAdapter(contentSource);
- }
- catch (Exception e) {
+ } catch (Exception e) {
log.warn("Failed to start adapator for content source [" +
contentSource + "]");
}
}
@@ -484,8 +465,7 @@ public class ContentProviderManager {
* @return the adapter that is communicating with the content source, isolated to its
classloader
* @throws RuntimeException if there is no content source adapter available
*/
- protected ContentProvider getIsolatedContentSourceAdapter(ContentSource
contentSource)
- throws RuntimeException {
+ protected ContentProvider getIsolatedContentSourceAdapter(ContentSource
contentSource) throws RuntimeException {
ContentProvider adapter;
synchronized (this.adapters) {
@@ -496,11 +476,9 @@ public class ContentProviderManager {
throw new RuntimeException("There is no adapter for content source
[" + adapter + "]");
}
- ServerPluginEnvironment env = this.pluginManager
- .getPluginEnvironment(contentSource.getContentSourceType());
+ ServerPluginEnvironment env =
this.pluginManager.getPluginEnvironment(contentSource.getContentSourceType());
if (env == null) {
- throw new RuntimeException(
- "There is no plugin env. for content source [" + contentSource
+ "]");
+ throw new RuntimeException("There is no plugin env. for content source
[" + contentSource + "]");
}
ClassLoader classLoader = env.getPluginClassLoader();
@@ -538,8 +516,7 @@ public class ContentProviderManager {
try {
ContentSourceType type = contentSource.getContentSourceType();
apiClassName = type.getContentSourceApiClass();
- pluginName = this.pluginManager.getMetadataManager()
- .getPluginNameFromContentSourceType(type);
+ pluginName =
this.pluginManager.getMetadataManager().getPluginNameFromContentSourceType(type);
ServerPluginEnvironment pluginEnv =
this.pluginManager.getPluginEnvironment(pluginName);
ClassLoader pluginClassloader = pluginEnv.getPluginClassLoader();
@@ -559,11 +536,8 @@ public class ContentProviderManager {
} finally {
Thread.currentThread().setContextClassLoader(startingClassLoader);
}
- }
- catch (Throwable t) {
- log.warn(
- "Failed to create the API class [" + apiClassName + "] for
plugin [" + pluginName +
- "]", t);
+ } catch (Throwable t) {
+ log.warn("Failed to create the API class [" + apiClassName +
"] for plugin [" + pluginName + "]", t);
}
if (adapter != null) {
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/ContentProviderSyncJob.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/ContentProviderSyncJob.java
index 7e864bf..c2cc916 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/ContentProviderSyncJob.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/ContentProviderSyncJob.java
@@ -52,6 +52,11 @@ public class ContentProviderSyncJob implements StatefulJob {
private static final Log log = LogFactory.getLog(ContentProviderSyncJob.class);
private static final String SEPARATOR = "--";
+ public int getPercentComplete() {
+ int retval = (int) (Math.random() * 100);
+ return retval;
+ }
+
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
JobDetail jobDetail = context.getJobDetail();
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java
index 47cb78f..0208014 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java
@@ -40,7 +40,7 @@ import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.content.Architecture;
import org.rhq.core.domain.content.ContentSource;
import org.rhq.core.domain.content.ContentSourceSyncResults;
-import org.rhq.core.domain.content.ContentSourceSyncStatus;
+import org.rhq.core.domain.content.ContentSyncStatus;
import org.rhq.core.domain.content.ContentSourceType;
import org.rhq.core.domain.content.DownloadMode;
import org.rhq.core.domain.content.InstalledPackage;
@@ -208,7 +208,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
// try to create another but this one is a FAILURE, this is allowed
another = new ContentSourceSyncResults(contentSource);
- another.setStatus(ContentSourceSyncStatus.FAILURE);
+ another.setStatus(ContentSyncStatus.FAILURE);
another.setEndTime(System.currentTimeMillis());
another = contentSourceManager.persistContentSourceSyncResults(another);
assert another != null : "Allowed to have two results persisted if only
one is INPROGRESS";
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java
index 13981eb..f545530 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java
@@ -35,14 +35,14 @@ import org.testng.annotations.Test;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.content.ContentSource;
-import org.rhq.core.domain.content.ContentSourceSyncResults;
-import org.rhq.core.domain.content.ContentSourceSyncStatus;
import org.rhq.core.domain.content.ContentSourceType;
+import org.rhq.core.domain.content.ContentSyncStatus;
import org.rhq.core.domain.content.Repo;
import org.rhq.core.domain.content.RepoGroup;
import org.rhq.core.domain.content.RepoGroupType;
import org.rhq.core.domain.content.RepoRelationshipType;
import org.rhq.core.domain.content.RepoRepoRelationship;
+import org.rhq.core.domain.content.RepoSyncResults;
import org.rhq.core.domain.criteria.RepoCriteria;
import org.rhq.core.domain.util.PageControl;
import org.rhq.core.domain.util.PageList;
@@ -50,10 +50,9 @@ import org.rhq.enterprise.server.content.ContentSourceManagerLocal;
import org.rhq.enterprise.server.content.RepoException;
import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.content.metadata.ContentSourceMetadataManagerLocal;
+import org.rhq.enterprise.server.plugin.pc.content.TestContentServerPluginService;
import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.util.LookupUtil;
-import org.rhq.enterprise.server.plugin.pc.ServerPluginServiceManagement;
-import org.rhq.enterprise.server.plugin.pc.content.TestContentServerPluginService;
public class RepoManagerBeanTest extends AbstractEJB3Test {
@@ -134,47 +133,34 @@ public class RepoManagerBeanTest extends AbstractEJB3Test {
@Test(enabled = ENABLED)
public void testSyncStatus() throws Exception {
Repo repo = new Repo("testSyncStatus");
- repoManager.createRepo(overlord, repo).getId();
+ repo = repoManager.createRepo(overlord, repo);
Calendar cal = Calendar.getInstance();
- ContentSourceType cst = new ContentSourceType("testSyncStatus");
- ContentSource cs = new ContentSource("testSyncStatus", cst);
- EntityManager em = getEntityManager();
- em.persist(cst);
- em.persist(cs);
-
for (int i = 0; i < 10; i++) {
cal.roll(Calendar.DATE, false);
- ContentSourceSyncResults results = new ContentSourceSyncResults(cs);
+ RepoSyncResults results = new RepoSyncResults(repo);
if (i % 2 == 0 && i != 0) {
System.out.println("Setting failed: i: [" + i +
"]");
- results.setStatus(ContentSourceSyncStatus.FAILURE);
+ results.setStatus(ContentSyncStatus.FAILURE);
} else {
- results.setStatus(ContentSourceSyncStatus.SUCCESS);
+ results.setStatus(ContentSyncStatus.SUCCESS);
}
results.setEndTime(cal.getTimeInMillis());
System.out.println("EndTime: " + new
Date(results.getEndTime().longValue()));
- em.persist(results);
- cs.addSyncResult(results);
+ repo.addSyncResult(results);
}
// Add one with no end time. This is to test NPE during sorting
- ContentSourceSyncResults results = new ContentSourceSyncResults(cs);
+ RepoSyncResults results = new RepoSyncResults(repo);
results.setStartTime(cal.getTimeInMillis());
- em.persist(results);
- cs.addSyncResult(results);
-
- repo.addContentSource(cs);
-
- em.flush();
- em.close();
+ repo.addSyncResult(results);
// Check sync status
- cs.getSyncResults();
+ repo.getSyncResults();
String status = repoManager.calculateSyncStatus(overlord, repo.getId());
- assert status.equals(ContentSourceSyncStatus.SUCCESS.toString());
+ assert status.equals(ContentSyncStatus.SUCCESS.toString());
}
@Test(enabled = ENABLED)