use of org.apache.myriad.scheduler.ServiceProfileManager in project incubator-myriad by apache.
the class Main method startNMInstances.
private void startNMInstances(Injector injector) {
Map<String, Integer> nmInstances = injector.getInstance(MyriadConfiguration.class).getNmInstances();
MyriadOperations myriadOperations = injector.getInstance(MyriadOperations.class);
ServiceProfileManager profileManager = injector.getInstance(ServiceProfileManager.class);
SchedulerState schedulerState = injector.getInstance(SchedulerState.class);
Set<org.apache.myriad.state.NodeTask> launchedNMTasks = new HashSet<>();
launchedNMTasks.addAll(schedulerState.getPendingTasksByType(NodeManagerConfiguration.DEFAULT_NM_TASK_PREFIX));
if (!launchedNMTasks.isEmpty()) {
LOGGER.info("{} NM(s) in pending state. Not launching additional NMs", launchedNMTasks.size());
return;
}
launchedNMTasks.addAll(schedulerState.getStagingTasksByType(NodeManagerConfiguration.DEFAULT_NM_TASK_PREFIX));
if (!launchedNMTasks.isEmpty()) {
LOGGER.info("{} NM(s) in staging state. Not launching additional NMs", launchedNMTasks.size());
return;
}
launchedNMTasks.addAll(schedulerState.getActiveTasksByType(NodeManagerConfiguration.DEFAULT_NM_TASK_PREFIX));
if (!launchedNMTasks.isEmpty()) {
LOGGER.info("{} NM(s) in active state. Not launching additional NMs", launchedNMTasks.size());
return;
}
for (Map.Entry<String, Integer> entry : nmInstances.entrySet()) {
LOGGER.info("Launching {} NM(s) with profile {}", entry.getValue(), entry.getKey());
myriadOperations.flexUpCluster(profileManager.get(entry.getKey()), entry.getValue(), null);
}
}
use of org.apache.myriad.scheduler.ServiceProfileManager in project incubator-myriad by apache.
the class Main method initProfiles.
private void initProfiles(Injector injector) {
LOGGER.info("Initializing Profiles");
ServiceProfileManager profileManager = injector.getInstance(ServiceProfileManager.class);
Map<String, Map<String, String>> profiles = injector.getInstance(MyriadConfiguration.class).getProfiles();
TaskUtils taskUtils = injector.getInstance(TaskUtils.class);
if (MapUtils.isNotEmpty(profiles)) {
for (Map.Entry<String, Map<String, String>> profile : profiles.entrySet()) {
Map<String, String> profileResourceMap = profile.getValue();
if (MapUtils.isNotEmpty(profiles) && profileResourceMap.containsKey("cpu") && profileResourceMap.containsKey("mem")) {
Long cpu = Long.parseLong(profileResourceMap.get("cpu"));
Long mem = Long.parseLong(profileResourceMap.get("mem"));
ServiceResourceProfile serviceProfile = new ExtendedResourceProfile(new NMProfile(profile.getKey(), cpu, mem), taskUtils.getNodeManagerCpus(), taskUtils.getNodeManagerMemory(), taskUtils.getNodeManagerPorts());
profileManager.add(serviceProfile);
} else {
LOGGER.error("Invalid definition for profile: " + profile.getKey());
}
}
}
}
use of org.apache.myriad.scheduler.ServiceProfileManager in project incubator-myriad by apache.
the class Main method initServiceConfigurations.
/**
* Create ServiceProfile for any configured service
*
* @param cfg
* @param injector
*/
private void initServiceConfigurations(MyriadConfiguration cfg, Injector injector) {
LOGGER.info("Initializing initServiceConfigurations");
ServiceProfileManager profileManager = injector.getInstance(ServiceProfileManager.class);
Map<String, ServiceConfiguration> servicesConfigs = injector.getInstance(MyriadConfiguration.class).getServiceConfigurations();
for (Map.Entry<String, ServiceConfiguration> entry : servicesConfigs.entrySet()) {
final String taskPrefix = entry.getKey();
ServiceConfiguration config = entry.getValue();
final Double cpu = config.getCpus();
final Double mem = config.getJvmMaxMemoryMB();
final Map<String, Long> ports = config.getPorts();
profileManager.add(new ServiceResourceProfile(taskPrefix, cpu, mem, ports));
}
}
use of org.apache.myriad.scheduler.ServiceProfileManager in project incubator-myriad by apache.
the class Main method validateNMInstances.
private void validateNMInstances(Injector injector) {
LOGGER.info("Validating nmInstances..");
Map<String, Integer> nmInstances = injector.getInstance(MyriadConfiguration.class).getNmInstances();
ServiceProfileManager profileManager = injector.getInstance(ServiceProfileManager.class);
long maxCpu = Long.MIN_VALUE;
long maxMem = Long.MIN_VALUE;
for (Map.Entry<String, Integer> entry : nmInstances.entrySet()) {
String profile = entry.getKey();
ServiceResourceProfile nodeManager = profileManager.get(profile);
if (nodeManager == null) {
throw new IllegalArgumentException("Invalid profile name '" + profile + "' specified in 'nmInstances'");
}
if (entry.getValue() > 0) {
if (nodeManager.getCpus() > maxCpu) {
// find the profile with largest number of cpus
maxCpu = nodeManager.getCpus().longValue();
// use the memory from the same profile
maxMem = nodeManager.getMemory().longValue();
}
}
}
if (maxCpu <= 0 || maxMem <= 0) {
throw new IllegalStateException("Please configure 'nmInstances' with at least one instance/profile " + "with non-zero cpu/mem resources.");
}
}
Aggregations