Skip to content

Commit 519b0ae

Browse files
committed
add XMLRCP API to schedule a supportdata action
1 parent 6c1f5f3 commit 519b0ae

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.redhat.rhn.domain.action.script.ScriptResult;
4848
import com.redhat.rhn.domain.action.script.ScriptRunAction;
4949
import com.redhat.rhn.domain.action.server.ServerAction;
50+
import com.redhat.rhn.domain.action.supportdata.UploadGeoType;
5051
import com.redhat.rhn.domain.channel.Channel;
5152
import com.redhat.rhn.domain.channel.ChannelArch;
5253
import com.redhat.rhn.domain.channel.ChannelFactory;
@@ -9189,6 +9190,45 @@ public CoCoAttestationResult getCoCoAttestationResultDetails(User loggedInUser,
91899190
}
91909191
}
91919192

9193+
/**
9194+
* Schedule Action to get and upload support data from the defined system to SCC.
9195+
* @param loggedInUser the user
9196+
* @param sid the system ID
9197+
* @param caseNumber the support case number
9198+
* @param parameter additional parameter for the tool which collect the data
9199+
* @param uploadGeo The location of the upload server [EU, US]
9200+
* @param earliestOccurrence the date when this action should be executed
9201+
* @return the action
9202+
*
9203+
* @apidoc.doc Schedule an action to get and upload support data from the specified system to SCC.
9204+
* @apidoc.param #session_key()
9205+
* @apidoc.param #param("int", "sid")
9206+
* @apidoc.param #param_desc("string", "caseNumber", "The SCC case number")
9207+
* @apidoc.param #param_desc("string", "parameter",
9208+
* "Additional parameter for the tool which collect the data from the system. Can be empty")
9209+
* @apidoc.param #param_desc("string", "uploadGeo", "The location of the upload server [EU, US]")
9210+
* @apidoc.param #param("$date", "earliestOccurrence")
9211+
* @apidoc.returntype #param_desc("int", "id", "ID of the action scheduled, otherwise exception thrown
9212+
* on error")
9213+
*/
9214+
public Integer scheduleSupportDataUpload(User loggedInUser, Integer sid, String caseNumber, String parameter,
9215+
String uploadGeo, Date earliestOccurrence) {
9216+
try {
9217+
SystemManager.lookupByIdAndUser(sid.longValue(), loggedInUser);
9218+
9219+
Action action = ActionManager.scheduleSupportDataAction(loggedInUser, sid.longValue(),
9220+
caseNumber, parameter, UploadGeoType.valueOf(uploadGeo), earliestOccurrence);
9221+
taskomaticApi.scheduleActionExecution(action);
9222+
return action.getId().intValue();
9223+
}
9224+
catch (LookupException e) {
9225+
throw new NoSuchSystemException();
9226+
}
9227+
catch (com.redhat.rhn.taskomatic.TaskomaticApiException eIn) {
9228+
throw new TaskomaticApiException(eIn.getMessage());
9229+
}
9230+
}
9231+
91929232
/**
91939233
* Only needed for unit tests.
91949234
* @return the {@link TaskomaticApi} instance used by this class

java/code/src/com/redhat/rhn/frontend/xmlrpc/system/test/SystemHandlerTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import com.redhat.rhn.domain.action.script.ScriptRunAction;
4747
import com.redhat.rhn.domain.action.server.ServerAction;
4848
import com.redhat.rhn.domain.action.server.test.ServerActionTest;
49+
import com.redhat.rhn.domain.action.supportdata.SupportDataAction;
50+
import com.redhat.rhn.domain.action.supportdata.SupportDataActionDetails;
4951
import com.redhat.rhn.domain.channel.Channel;
5052
import com.redhat.rhn.domain.channel.ChannelFactory;
5153
import com.redhat.rhn.domain.channel.ChannelFamily;
@@ -237,6 +239,24 @@ public void setUp() throws Exception {
237239
super.setUp();
238240
}
239241

242+
@Test
243+
public void testCreateSupportdataAction() throws Exception {
244+
Server server = ServerFactoryTest.createTestServer(admin, true);
245+
246+
Integer aid = handler.scheduleSupportDataUpload(admin, server.getId().intValue(),
247+
"012345", "-i LVM", "EU", getNow());
248+
assertNotNull(aid);
249+
250+
Action action = ActionFactory.lookupById(Long.valueOf(aid));
251+
assertEquals(ActionFactory.TYPE_SUPPORTDATA_GET, action.getActionType());
252+
assertEquals("Get and Upload Support data", action.getName());
253+
SupportDataActionDetails details = ((SupportDataAction) action).getDetails();
254+
assertNotNull(details);
255+
assertEquals("012345", details.getCaseNumber());
256+
assertEquals("-i LVM", details.getParameter());
257+
assertEquals("EU", details.getGeoType().name());
258+
}
259+
240260
@Test
241261
public void testGetNetworkDevices() throws Exception {
242262
Server server = ServerFactoryTest.createTestServer(admin, true);

java/code/src/com/redhat/rhn/manager/action/ActionManager.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
import com.redhat.rhn.domain.action.script.ScriptActionDetails;
5757
import com.redhat.rhn.domain.action.script.ScriptRunAction;
5858
import com.redhat.rhn.domain.action.server.ServerAction;
59+
import com.redhat.rhn.domain.action.supportdata.SupportDataAction;
60+
import com.redhat.rhn.domain.action.supportdata.SupportDataActionDetails;
61+
import com.redhat.rhn.domain.action.supportdata.UploadGeoType;
5962
import com.redhat.rhn.domain.common.FileList;
6063
import com.redhat.rhn.domain.config.ConfigChannel;
6164
import com.redhat.rhn.domain.config.ConfigFileName;
@@ -2517,6 +2520,38 @@ public static List<Long> changeProxy(User loggedInUser, List<Long> sysids, Long
25172520
return ret;
25182521
}
25192522

2523+
/**
2524+
* Schedule Action to get and upload supportdata from the defined system to SCC.
2525+
* @param scheduler the scheduler of this action
2526+
* @param sid the system ID
2527+
* @param caseNumber the support case number
2528+
* @param parameter additional parameter for the tool which collect the data
2529+
* @param uploadGeoType the uploadGeo Type
2530+
* @param earliest the date when this action should be executed
2531+
* @return the action
2532+
*/
2533+
public static Action scheduleSupportDataAction(User scheduler, long sid, String caseNumber, String parameter,
2534+
UploadGeoType uploadGeoType, Date earliest) {
2535+
SupportDataAction action = (SupportDataAction) ActionFactory
2536+
.createAction(ActionFactory.TYPE_SUPPORTDATA_GET, earliest);
2537+
action.setName("Get and Upload Support data");
2538+
action.setOrg(scheduler != null ?
2539+
scheduler.getOrg() : OrgFactory.getSatelliteOrg());
2540+
action.setSchedulerUser(scheduler);
2541+
2542+
SupportDataActionDetails actionDetails = new SupportDataActionDetails();
2543+
actionDetails.setCaseNumber(caseNumber);
2544+
actionDetails.setParameter(parameter);
2545+
actionDetails.setGeoType(uploadGeoType);
2546+
actionDetails.setParentAction(action);
2547+
2548+
action.setDetails(actionDetails);
2549+
ActionFactory.save(action);
2550+
2551+
scheduleForExecution(action, Set.of(sid));
2552+
return action;
2553+
}
2554+
25202555
/**
25212556
* Schedule an immediate Ansible inventory refresh without a user.
25222557
*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Implement API to get and upload support data to SCC

0 commit comments

Comments
 (0)