java/code/src/com/redhat/rhn/domain/iss/IssFactory.java
| 21 ++
java/code/src/com/redhat/rhn/domain/iss/IssMaster.hbm.xml
| 10 +
java/code/src/com/redhat/rhn/domain/iss/IssMaster.java
| 61 ++++++
java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/IssMasterSerializer.java
| 4
java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/test/IssMasterSerializerTest.java
| 6
java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/MasterHandler.java
| 66 +++++++
java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/test/MasterHandlerTest.java
| 93 ++++++++++
7 files changed, 261 insertions(+)
New commits:
commit d10a65cfb42188e43a929a2f1b0287a1dc58388e
Author: Grant Gainey <ggainey(a)redhat.com>
Date: Wed Jul 3 12:04:07 2013 -0400
977878 - Support for is_current and ca_cert, DTO/Serializer/Handler
diff --git a/java/code/src/com/redhat/rhn/domain/iss/IssFactory.java
b/java/code/src/com/redhat/rhn/domain/iss/IssFactory.java
index d9ffd40..66eeeeb 100644
--- a/java/code/src/com/redhat/rhn/domain/iss/IssFactory.java
+++ b/java/code/src/com/redhat/rhn/domain/iss/IssFactory.java
@@ -119,6 +119,27 @@ public class IssFactory extends HibernateFactory {
}
/**
+ * Return current default master for this slave
+ * @return master where master.isDefaultMaster() == true, null else
+ */
+ public static IssMaster getCurrentMaster() {
+ Map params = new HashMap();
+ return (IssMaster) singleton.lookupObjectByNamedQuery(
+ "IssMaster.lookupDefaultMaster", params);
+ }
+
+ /**
+ * Unset whatever the 'current' master is, no matter who holds it currently
+ */
+ public static void unsetCurrentMaster() {
+ IssMaster m = getCurrentMaster();
+ if (m != null) {
+ m.unsetAsDefault();
+ save(m);
+ }
+ }
+
+ /**
* IssMasterOrg helpers
*/
diff --git a/java/code/src/com/redhat/rhn/domain/iss/IssMaster.hbm.xml
b/java/code/src/com/redhat/rhn/domain/iss/IssMaster.hbm.xml
index aa616e7..b433301 100644
--- a/java/code/src/com/redhat/rhn/domain/iss/IssMaster.hbm.xml
+++ b/java/code/src/com/redhat/rhn/domain/iss/IssMaster.hbm.xml
@@ -13,6 +13,8 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
</id>
<property name="label" column="LABEL"
type="string" length="256" />
+ <property name="isCurrentMaster"
column="IS_CURRENT_MASTER" type="string" length="1" />
+ <property name="caCert" column="CA_CERT"
type="string" length="1024" />
<set name="masterOrgs"
inverse="true"
@@ -35,4 +37,12 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<![CDATA[from com.redhat.rhn.domain.iss.IssMaster as m order by m.label]]>
</query>
+ <query name="IssMaster.lookupDefaultMaster">
+ <![CDATA[from com.redhat.rhn.domain.iss.IssMaster where isCurrentMaster =
'Y']]>
+ </query>
+
+ <query name="IssMaster.unsetCurrent">
+ <![CDATA[update com.redhat.rhn.domain.iss.IssMaster set isCurrentMaster =
'N' where isCurrentMaster = 'Y']]>
+ </query>
+
</hibernate-mapping>
diff --git a/java/code/src/com/redhat/rhn/domain/iss/IssMaster.java
b/java/code/src/com/redhat/rhn/domain/iss/IssMaster.java
index 7eab4cd..06ca8e6 100644
--- a/java/code/src/com/redhat/rhn/domain/iss/IssMaster.java
+++ b/java/code/src/com/redhat/rhn/domain/iss/IssMaster.java
@@ -32,6 +32,8 @@ public class IssMaster extends BaseDto {
private Long id;
private String label;
+ private String isCurrentMaster = "N";
+ private String caCert;
private Set<IssMasterOrg> masterOrgs = new HashSet<IssMasterOrg>();
/**
@@ -67,6 +69,65 @@ public class IssMaster extends BaseDto {
}
/**
+ * Get filename of CA Certificate for this master
+ * @return filename
+ */
+ public String getCaCert() {
+ return caCert;
+ }
+
+ /**
+ * Set filename of the CA Cert for this master
+ * @param caCertIn path to the CA cert for this master
+ */
+ public void setCaCert(String caCertIn) {
+ this.caCert = caCertIn;
+ }
+
+ /**
+ * Is this master the current-default for the Slave we're on?
+ * @return 'Y' is we're the default, 'N' else
+ */
+ protected String getIsCurrentMaster() {
+ return isCurrentMaster;
+ }
+
+ /**
+ * Set this master as default, or not
+ * NOTE: FOR HIBERNATE ONLY, use #makeDefaultMaster() instead
+ * @param isCurrentIn - 'Y' if this is the default, 'N' else
+ */
+ protected void setIsCurrentMaster(String isCurrentIn) {
+ this.isCurrentMaster = isCurrentIn;
+ }
+
+ /**
+ * Make this master the default for this slave's satellite-sync operations
+ */
+ public void makeDefaultMaster() {
+ IssFactory.unsetCurrentMaster();
+ this.setIsCurrentMaster("Y");
+ }
+
+ /**
+ * Make sure this master is NOT the default for satellite-sync
+ * NOTE: Preferred is to make someone else the default -but sometimes, you
+ * just don't want a default...
+ */
+ public void unsetAsDefault() {
+ this.setIsCurrentMaster("N");
+ }
+
+ /**
+ * Is this master the default for this slave's satellite-sync?
+ * @return true if this is the master satellite-sync will use in the absence of
+ * other info
+ */
+ public boolean isDefaultMaster() {
+ return "Y".equals(this.getIsCurrentMaster());
+ }
+
+ /**
* Get Orgs this master has let us know about
* @return list of orgs Master has told us about
*/
diff --git
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/IssMasterSerializer.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/IssMasterSerializer.java
index 754233f..84d4b43 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/IssMasterSerializer.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/IssMasterSerializer.java
@@ -32,6 +32,8 @@ import com.redhat.rhn.frontend.xmlrpc.serializer.util.SerializerHelper;
* #struct("IssMaster info")
* #prop("int", "id")
* #prop("string", "label")
+ * #prop("string", "caCert")
+ * #prop("boolean", "isCurrentMaster")
* #struct_end()
*/
public class IssMasterSerializer implements XmlRpcCustomSerializer {
@@ -53,6 +55,8 @@ public class IssMasterSerializer implements XmlRpcCustomSerializer {
IssMaster master = (IssMaster) obj;
helper.add("id", master.getId());
helper.add("label", master.getLabel());
+ helper.add("caCert", master.getCaCert());
+ helper.add("isCurrentMaster", master.isDefaultMaster());
helper.writeTo(writer);
}
diff --git
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/test/IssMasterSerializerTest.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/test/IssMasterSerializerTest.java
index 490bfda..4fb647a 100644
---
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/test/IssMasterSerializerTest.java
+++
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/test/IssMasterSerializerTest.java
@@ -48,6 +48,10 @@ public class IssMasterSerializerTest extends MockObjectTestCase {
assertTrue(result.contains(">" + master.getId() +
"<"));
assertTrue(result.contains("name>label</name"));
assertTrue(result.contains(">" + master.getLabel() +
"<"));
+ assertTrue(result.contains("name>isCurrentMaster</name"));
+ assertTrue(result.contains(">" + (master.isDefaultMaster() ?
"1" : "0") + "<"));
+ assertTrue(result.contains("name>caCert</name"));
+ assertTrue(result.contains(">" + (master.getCaCert()) +
"<"));
}
public void testMasterOrgSerialize() throws XmlRpcException, IOException {
@@ -71,6 +75,8 @@ public class IssMasterSerializerTest extends MockObjectTestCase {
IssMaster master = new IssMaster();
master.setLabel("testMaster" + TestUtils.randomString());
+ master.makeDefaultMaster();
+ master.setCaCert("/tmp/FOO-CA-CERT");
Set<IssMasterOrg> orgs = new HashSet<IssMasterOrg>();
for (String orgName : masterOrgNames) {
IssMasterOrg anOrg = new IssMasterOrg();
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/MasterHandler.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/MasterHandler.java
index 2b77372..42ebae5 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/MasterHandler.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/MasterHandler.java
@@ -124,6 +124,72 @@ public class MasterHandler extends BaseHandler {
}
/**
+ * Make the specified Master the default for this Slave's satellite-sync
+ * @param sessionKey User's session key.
+ * @param masterId Id of the Master to be the default
+ * @return 1 on success, exception otherwise
+ *
+ * @xmlrpc.doc Make the specified Master the default for this Slave's
satellite-sync
+ * @xmlrpc.param #param("string", "sessionKey")
+ * @xmlrpc.param #param_desc("int", "id", "Id of the Master
to make the default")
+ * @xmlrpc.returntype #return_int_success()
+ */
+ public int makeDefault(String sessionKey, Integer masterId) {
+ IssMaster master = getMaster(sessionKey, masterId);
+ master.makeDefaultMaster();
+ return 1;
+ }
+
+ /**
+ * Return the current default-master for this slave
+ * @param sessionKey User's session key
+ * @return current default master, null if there isn't one
+ *
+ * @xmlrpc.doc Return the current default-master for this slave
+ * @xmlrpc.param #param("string", "sessionKey")
+ * @xmlrpc.returntype $IssMasterSerializer
+ */
+ public IssMaster getDefaultMaster(String sessionKey) {
+ ensureSatAdmin(getLoggedInUser(sessionKey));
+ return IssFactory.getCurrentMaster();
+ }
+
+ /**
+ * Make this slave have no default Master for satellite-sync
+ * @param sessionKey User's session key.
+ * @return 1 on success, exception otherwise
+ *
+ * @xmlrpc.doc Make this slave have no default Master for satellite-sync
+ * @xmlrpc.param #param("string", "sessionKey")
+ * @xmlrpc.returntype #return_int_success()
+ */
+ public int unsetDefaultMaster(String sessionKey) {
+ ensureSatAdmin(getLoggedInUser(sessionKey));
+ IssFactory.unsetCurrentMaster();
+ return 1;
+ }
+
+ /**
+ * Set the CA-CERT filename for specified Master on this Slave
+ * @param sessionKey User's session key.
+ * @param masterId Id of the Master we're affecting
+ * @param caCertFilename path to this Master's CA Cert on this Slave
+ * @return 1 on success, exception otherwise
+ *
+ * @xmlrpc.doc Make the specified Master the default for this Slave's
satellite-sync
+ * @xmlrpc.param #param("string", "sessionKey")
+ * @xmlrpc.param #param_desc("int", "id", "Id of the Master
to affect")
+ * @xmlrpc.param #param_desc("string", "caCertFilename",
+ * "path to specified Master's CA cert")
+ * @xmlrpc.returntype #return_int_success()
+ */
+ public int setCaCert(String sessionKey, Integer masterId, String caCertFilename) {
+ IssMaster master = getMaster(sessionKey, masterId);
+ master.setCaCert(caCertFilename);
+ return 1;
+ }
+
+ /**
* Find a Master by specifying its ID
* @param sessionKey User's session key.
* @param masterId Id of the Master to look for
diff --git
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/test/MasterHandlerTest.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/test/MasterHandlerTest.java
index 0aa78c7..9396eba 100644
---
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/test/MasterHandlerTest.java
+++
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/sync/master/test/MasterHandlerTest.java
@@ -87,6 +87,99 @@ public class MasterHandlerTest extends BaseHandlerTestCase {
}
}
+ public void testCaCert() {
+ IssMaster master = handler.create(adminKey, masterName);
+ Integer mstrId = master.getId().intValue();
+
+ // Make sure that non-sat-admin users cannot access
+ try {
+ int rc = handler.setCaCert(regularKey, mstrId, "/tmp/foo");
+ fail();
+ }
+ catch (PermissionCheckFailureException e) {
+ //success
+ }
+
+ // Make sure satellite-admin can
+ try {
+ int rc = handler.setCaCert(adminKey, mstrId, "/tmp/foo");
+ IssMaster gotMaster = handler.getMaster(adminKey, mstrId);
+ assertEquals("/tmp/foo", gotMaster.getCaCert());
+ }
+ catch (PermissionCheckFailureException e) {
+ fail();
+ }
+ }
+
+ public void testMasterDefault() {
+ String masterName1 = "testMaster" + TestUtils.randomString();
+ String masterName2 = "testMaster" + TestUtils.randomString();
+ String masterName3 = "testMaster" + TestUtils.randomString();
+
+ IssMaster master1 = handler.create(adminKey, masterName1);
+ IssMaster master2 = handler.create(adminKey, masterName2);
+ IssMaster master3 = handler.create(adminKey, masterName3);
+
+ // Make sure that non-sat-admin users cannot do any of the
+ // master-default APIs
+ try {
+ IssMaster retMaster = handler.getDefaultMaster(regularKey);
+ fail();
+ }
+ catch (PermissionCheckFailureException e) {
+ // success
+ }
+ try {
+ int rc = handler.makeDefault(regularKey, master1.getId().intValue());
+ fail();
+ }
+ catch (PermissionCheckFailureException e) {
+ // success
+ }
+
+ try {
+ int rc = handler.unsetDefaultMaster(regularKey);
+ fail();
+ }
+ catch (PermissionCheckFailureException e) {
+ // success
+ }
+
+ // Make sure satellite-admin can
+ try {
+ IssMaster retMaster = handler.getDefaultMaster(adminKey);
+ assertNull(retMaster);
+
+ int rc = handler.makeDefault(adminKey, master1.getId().intValue());
+ assertEquals(1, rc);
+ retMaster = handler.getDefaultMaster(adminKey);
+ assertNotNull(retMaster);
+ assertTrue(retMaster.getId().equals(master1.getId()));
+
+ rc = handler.makeDefault(adminKey, master3.getId().intValue());
+ assertEquals(1, rc);
+ retMaster = handler.getDefaultMaster(adminKey);
+ assertNotNull(retMaster);
+ assertTrue(retMaster.getId().equals(master3.getId()));
+
+ retMaster = handler.getMaster(adminKey, master1.getId().intValue());
+ assertNotNull(retMaster);
+ assertFalse(retMaster.isDefaultMaster());
+
+ rc = handler.unsetDefaultMaster(adminKey);
+ assertEquals(1, rc);
+ retMaster = handler.getMaster(adminKey, master3.getId().intValue());
+ assertNotNull(retMaster);
+ assertFalse(retMaster.isDefaultMaster());
+
+ retMaster = handler.getDefaultMaster(adminKey);
+ assertNull(retMaster);
+ }
+ catch (PermissionCheckFailureException e) {
+ fail();
+ }
+ }
+
public void testDelete() {
IssMaster master = handler.create(adminKey, masterName);
Long mstrId = master.getId();