private void scheduleInstalls(SsmInstallPackagesEvent event, User user) {

    log.debug("Scheduling package installations.");
    Date earliest = event.getEarliest();
    Set<String> data = event.getPackages();
    Long channelId = event.getChannelId();

    List<EssentialServerDto> servers =
        SystemManager.systemsSubscribedToChannelInSet(channelId, user, SetLabels.SYSTEM_LIST);

    // Convert the package list to domain objects
    List<PackageListItem> packageListItems = new ArrayList<PackageListItem>(data.size());
    for (String key : data) {
      packageListItems.add(PackageListItem.parse(key));
    }

    // Convert to list of maps
    List<Map<String, Long>> packageListData = PackageListItem.toKeyMaps(packageListItems);

    // Create one action for all servers to which the packages are installed
    List<Long> serverIds = new LinkedList<Long>();
    for (EssentialServerDto dto : servers) {
      serverIds.add(dto.getId());
    }

    log.debug("Scheduling actions.");
    ActionManager.schedulePackageInstall(user, serverIds, packageListData, earliest);
    log.debug("Done scheduling package installations.");
  }
  protected List<Long> getAffectedServers(SsmPackageEvent event, User u) {
    SsmInstallPackagesEvent sipe = (SsmInstallPackagesEvent) event;
    Long channelId = sipe.getChannelId();

    List<EssentialServerDto> servers =
        SystemManager.systemsSubscribedToChannelInSet(channelId, u, SetLabels.SYSTEM_LIST);

    // Create one action for all servers to which the packages are installed
    List<Long> serverIds = new LinkedList<Long>();
    for (EssentialServerDto dto : servers) {
      serverIds.add(dto.getId());
    }
    return serverIds;
  }
  protected List<Action> doSchedule(
      SsmPackageEvent event, User user, List<Long> sids, Date earliest, ActionChain actionChain) {
    SsmInstallPackagesEvent sipe = (SsmInstallPackagesEvent) event;

    Set<String> data = sipe.getPackages();
    // Convert the package list to domain objects
    List<PackageListItem> pkgListItems = new ArrayList<PackageListItem>(data.size());
    for (String key : data) {
      pkgListItems.add(PackageListItem.parse(key));
    }

    // Convert to list of maps
    List<Map<String, Long>> packageListData = PackageListItem.toKeyMaps(pkgListItems);

    return ActionChainManager.schedulePackageInstalls(
        user, sids, packageListData, earliest, actionChain);
  }
  protected void doExecute(EventMessage msg) {
    SsmInstallPackagesEvent event = (SsmInstallPackagesEvent) msg;

    User user = UserFactory.lookupById(event.getUserId());

    // Log the action has been created
    long operationId =
        SsmOperationManager.createOperation(
            user, "ssm.package.install.operationname", RhnSetDecl.SYSTEMS.getLabel());

    try {
      scheduleInstalls(event, user);
    } catch (Exception e) {
      log.error("Error scheduling package installations for event " + event, e);
    } finally {
      // This should stay in the finally block so the operation is
      // not perpetually left in an in progress state
      SsmOperationManager.completeOperation(user, operationId);
    }
  }