@RequiredPermissions({ @RequiredPermission(Permission.MANAGE_SETTINGS),
@RequiredPermission(Permission.MANAGE_INVENTORY) })
public void addServersToGroup(Subject subject, int affinityGroupId, Integer[] serverIds) {
List<Integer> serverIdsList = Arrays.asList(serverIds);
AffinityGroup group = entityManager.find(AffinityGroup.class, affinityGroupId);
Query query = entityManager.createNamedQuery(AffinityGroup.QUERY_UPDATE_ADD_SERVERS);
query.setParameter("affinityGroup", group);
query.setParameter("serverIds", serverIdsList);
query.executeUpdate();
// Audit each changed affinity group assignment (is this too verbose?)
String auditString = group.getName() + " <-- ";
for (Integer serverId : serverIdsList) {
Server server = entityManager.find(Server.class, serverId);
partitionEventManager.auditPartitionEvent(subject, PartitionEventType.SERVER_AFFINITY_GROUP_ASSIGN,
auditString + server.getName());
}
// Now, request a cloud repartitioning due to the affinity group changes
partitionEventManager.cloudPartitionEventRequest(subject, PartitionEventType.AFFINITY_GROUP_CHANGE, group
.getName());
}