/** * Calculates summary RAM of given {@link Runtime}. * * @return summary RAM of all machines in runtime in megabytes */ public long calculate(Runtime runtime) { return runtime .getMachines() .values() .stream() .mapToLong( m -> parseMemoryAttributeValue(m.getAttributes().get(MEMORY_LIMIT_ATTRIBUTE))) .sum() / BYTES_TO_MEGABYTES_DIVIDER; }
public MachineImpl(String name, Machine machine) { this(name, machine.getAttributes(), machine.getServers(), machine.getStatus()); }
public MachineImpl(Machine machineRuntime) { this(machineRuntime.getAttributes(), machineRuntime.getServers(), machineRuntime.getStatus()); }
/** * Returns map of machine name to machine instance entries. * * @throws InfrastructureException when any error occurs */ public Map<String, ? extends Machine> getMachines() throws InfrastructureException { return getInternalMachines() .entrySet() .stream() .collect( toMap( Map.Entry::getKey, e -> new MachineImpl( e.getValue().getAttributes(), rewriteExternalServers(e.getKey(), e.getValue().getServers()), e.getValue().getStatus()))); }
/** Converts {@link Machine} to {@link MachineDto}. */ public static MachineDto asDto(Machine machine) { MachineDto machineDto = newDto(MachineDto.class) .withAttributes(machine.getAttributes()) .withStatus(machine.getStatus()); if (machine.getServers() != null) { machineDto.withServers( machine .getServers() .entrySet() .stream() .collect(toMap(Map.Entry::getKey, entry -> asDto(entry.getValue())))); } return machineDto; }