Search in sources :

Example 1 with ServiceProfileManager

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);
    }
}
Also used : ServiceProfileManager(org.apache.myriad.scheduler.ServiceProfileManager) SchedulerState(org.apache.myriad.state.SchedulerState) MyriadConfiguration(org.apache.myriad.configuration.MyriadConfiguration) Map(java.util.Map) MyriadOperations(org.apache.myriad.scheduler.MyriadOperations) HashSet(java.util.HashSet)

Example 2 with ServiceProfileManager

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());
            }
        }
    }
}
Also used : ServiceProfileManager(org.apache.myriad.scheduler.ServiceProfileManager) ExtendedResourceProfile(org.apache.myriad.scheduler.ExtendedResourceProfile) TaskUtils(org.apache.myriad.scheduler.TaskUtils) NMProfile(org.apache.myriad.scheduler.NMProfile) MyriadConfiguration(org.apache.myriad.configuration.MyriadConfiguration) ServiceResourceProfile(org.apache.myriad.scheduler.ServiceResourceProfile) Map(java.util.Map)

Example 3 with ServiceProfileManager

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));
    }
}
Also used : ServiceProfileManager(org.apache.myriad.scheduler.ServiceProfileManager) ServiceConfiguration(org.apache.myriad.configuration.ServiceConfiguration) MyriadConfiguration(org.apache.myriad.configuration.MyriadConfiguration) ServiceResourceProfile(org.apache.myriad.scheduler.ServiceResourceProfile) Map(java.util.Map)

Example 4 with ServiceProfileManager

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.");
    }
}
Also used : ServiceProfileManager(org.apache.myriad.scheduler.ServiceProfileManager) MyriadConfiguration(org.apache.myriad.configuration.MyriadConfiguration) ServiceResourceProfile(org.apache.myriad.scheduler.ServiceResourceProfile) Map(java.util.Map)

Aggregations

Map (java.util.Map)4 MyriadConfiguration (org.apache.myriad.configuration.MyriadConfiguration)4 ServiceProfileManager (org.apache.myriad.scheduler.ServiceProfileManager)4 ServiceResourceProfile (org.apache.myriad.scheduler.ServiceResourceProfile)3 HashSet (java.util.HashSet)1 ServiceConfiguration (org.apache.myriad.configuration.ServiceConfiguration)1 ExtendedResourceProfile (org.apache.myriad.scheduler.ExtendedResourceProfile)1 MyriadOperations (org.apache.myriad.scheduler.MyriadOperations)1 NMProfile (org.apache.myriad.scheduler.NMProfile)1 TaskUtils (org.apache.myriad.scheduler.TaskUtils)1 SchedulerState (org.apache.myriad.state.SchedulerState)1