String[] cmd = getDeployableCommandLine(cmdLine,processEnv);
if ( isKillCommand(cmdLine) ) {
logger.info(methodName, null, "Killing process");
stopProcess(cmdLine, cmd);
} else {
IDuccProcess duccProcess = ((ManagedProcess) managedProcess).getDuccProcess();
// If running a real agent on a node, collect swap info and assign max swap usage threshold
// for each process. In virtual mode, where there are multiple agents per node, we dont
// set nor enforce swap limits.
if ( !agent.virtualAgent) {
// Calculate how much swap space the process is allowed to use. The calculation is based on
// the percentage of real memory the process is assigned. The process is entitled the
// same percentage of the swap.
// Normalize node's total memory as it is expressed in KB. The calculation below is based on bytes.
double percentOfTotal = ((double)duccProcess.getCGroup().getMaxMemoryLimit())/
(agent.getNodeInfo().getNodeMetrics().getNodeMemory().getMemTotal()*1024); // need bytes
// substract 1Gig from total swap on this node to accommodate OS needs for swapping. The
// getSwapTotal() returns swap space in KBs so normalize 1Gig
long adjustedTotalSwapAvailable =
agent.getNodeInfo().getNodeMetrics().getNodeMemory().getSwapTotal() - 1048576;
// calculate the portion (in bytes) of swap this process is entitled to
long maxProcessSwapUsage =
(long) (adjustedTotalSwapAvailable*percentOfTotal)*1024;
// assigned how much swap this process is entitled to. If it exceeds this number the Agent
// will kill the process.
((ManagedProcess) managedProcess).setMaxSwapThreshold(maxProcessSwapUsage);
logger.info(methodName, null, "---Process DuccId:"+duccProcess.getDuccId()+
" CGroup.getMaxMemoryLimit():"+((duccProcess.getCGroup().getMaxMemoryLimit()/1024)/1024)+" MBs"+
" Node Memory Total:"+(agent.getNodeInfo().getNodeMetrics().getNodeMemory().getMemTotal()/1024)+" MBs"+
" Percentage Of Real Memory:"+percentOfTotal+
" Adjusted Total Swap Available On Node:"+adjustedTotalSwapAvailable/1024+" MBs"+
" Process Entitled To Max:"+(maxProcessSwapUsage/1024)/1024+" MBs of Swap"
);
//logger.info(methodName, null, "The Process With ID:"+duccProcess.getDuccId()+" is Entitled to the Max "+( (maxProcessSwapUsage/1024)/1024)+" Megs of Swap Space");
// if configured to use cgroups and the process is the cgroup owner, create a cgroup
// using Process DuccId as a name. Additional processes may be injected into the
// cgroup by declaring cgroup owner id.
if ( agent.useCgroups ) {
// JDs are of type Pop (Plain Old Process). JDs run in a reservation. The cgroup container
// is created for the reservation and we co-locate as many JDs as we can fit in it.
//String containerId = ((ManagedProcess) managedProcess).getWorkDuccId()+"."+duccProcess.getCGroup().getId().getFriendly();
String containerId = getContainerId();
logger.info(methodName, null, "Creating CGroup with ID:"+containerId);
if ( !agent.cgroupsManager.cgroupExists(agent.cgroupsManager.getDuccCGroupBaseDir()+"/"+containerId) ) {
boolean failed = false;
// create cgroup container for JDs
try {
if ( createCGroupContainer(duccProcess, containerId, ((ManagedProcess)super.managedProcess).getOwner()) ) {
logger.info(methodName, null, "Created CGroup with ID:"+containerId+" With Memory Limit="+((ManagedProcess)super.managedProcess).getDuccProcess().getCGroup().getMaxMemoryLimit()+" Bytes");
} else {
logger.info(methodName, null, "Failed To Create CGroup with ID:"+containerId);
duccProcess.setProcessState(ProcessState.Failed);
duccProcess.setReasonForStoppingProcess("CGroupCreationFailed");
failed = true;
agent.stop();
}
} catch( Exception e) {
logger.error(methodName, null, e);
failed = true;
agent.stop();
}
if ( failed ) {
throw new RuntimeException("The Agent is Unable To Create A CGroup with Container ID: "+containerId+". Rejecting Deployment of Process with ID:"+duccProcess.getDuccId());
}
} else {
logger.info(methodName, null, "CGroup Exists with ID:"+containerId);
}