Search in sources :

Example 1 with ServiceConfiguration

use of org.apache.myriad.configuration.ServiceConfiguration in project incubator-myriad by apache.

the class MyriadTestModule method configure.

@SuppressWarnings("unchecked")
@Override
protected void configure() {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    try {
        cfg = mapper.readValue(Thread.currentThread().getContextClassLoader().getResource("myriad-config-test-default.yml"), MyriadConfiguration.class);
    } catch (IOException e1) {
        LOGGER.error("IOException", e1);
        return;
    }
    if (cfg == null) {
        return;
    }
    bind(MyriadConfiguration.class).toInstance(cfg);
    MapBinder<String, TaskFactory> mapBinder = MapBinder.newMapBinder(binder(), String.class, TaskFactory.class);
    mapBinder.addBinding(NodeManagerConfiguration.DEFAULT_NM_TASK_PREFIX).to(NMTaskFactory.class).in(Scopes.SINGLETON);
    Map<String, ServiceConfiguration> auxServicesConfigs = cfg.getServiceConfigurations();
    for (Map.Entry<String, ServiceConfiguration> entry : auxServicesConfigs.entrySet()) {
        String taskFactoryClass = entry.getValue().getTaskFactoryImplName().orNull();
        if (taskFactoryClass != null) {
            try {
                Class<? extends TaskFactory> implClass = (Class<? extends TaskFactory>) Class.forName(taskFactoryClass);
                mapBinder.addBinding(entry.getKey()).to(implClass).in(Scopes.SINGLETON);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        } else {
            mapBinder.addBinding(entry.getKey()).to(ServiceTaskFactory.class).in(Scopes.SINGLETON);
        }
    }
}
Also used : IOException(java.io.IOException) ServiceTaskFactory(org.apache.myriad.scheduler.ServiceTaskFactory) MyriadConfiguration(org.apache.myriad.configuration.MyriadConfiguration) ServiceConfiguration(org.apache.myriad.configuration.ServiceConfiguration) TaskFactory(org.apache.myriad.scheduler.TaskFactory) ServiceTaskFactory(org.apache.myriad.scheduler.ServiceTaskFactory) NMTaskFactory(org.apache.myriad.scheduler.NMTaskFactory) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NMTaskFactory(org.apache.myriad.scheduler.NMTaskFactory)

Example 2 with ServiceConfiguration

use of org.apache.myriad.configuration.ServiceConfiguration in project incubator-myriad by apache.

the class MyriadOperations method flexUpAService.

/**
 * Flexup a service
 *
 * @param instances
 * @param serviceName
 *
 * @throws MyriadBadConfigurationException if total number of instances in active, staging, and pending
 *                                         states exceeds the ServiceConfiguration.maxInstances
 */
public void flexUpAService(int instances, String serviceName) throws MyriadBadConfigurationException {
    final ServiceConfiguration auxTaskConf = cfg.getServiceConfiguration(serviceName).get();
    if (auxTaskConf.getMaxInstances().isPresent()) {
        // If total number of current and flex instances exceed maxInstances, throw an exception
        int totalflexInstances = instances + getFlexibleInstances(serviceName);
        Integer maxInstances = auxTaskConf.getMaxInstances().get();
        if (maxInstances > 0) {
            if (totalflexInstances > maxInstances) {
                LOGGER.error("Current number of active, staging, pending and requested instances: {}" + ", while it is greater then max instances allowed: {}", totalflexInstances, maxInstances);
                throw new MyriadBadConfigurationException("Current number of active, staging, pending instances and requested: " + totalflexInstances + ", while it is greater then max instances allowed: " + maxInstances);
            }
        }
    }
    final Double cpu = auxTaskConf.getCpus();
    final Double mem = auxTaskConf.getJvmMaxMemoryMB();
    Collection<NodeTask> nodes = new HashSet<>();
    for (int i = 0; i < instances; i++) {
        NodeTask nodeTask = new NodeTask(new ServiceResourceProfile(serviceName, cpu, mem, auxTaskConf.getPorts()), null);
        nodeTask.setTaskPrefix(serviceName);
        nodes.add(nodeTask);
    }
    LOGGER.info("Adding {} {} instances to cluster", nodes.size(), serviceName);
    this.schedulerState.addNodes(nodes);
}
Also used : ServiceConfiguration(org.apache.myriad.configuration.ServiceConfiguration) MyriadBadConfigurationException(org.apache.myriad.configuration.MyriadBadConfigurationException) NodeTask(org.apache.myriad.state.NodeTask) LikeConstraint(org.apache.myriad.scheduler.constraints.LikeConstraint) Constraint(org.apache.myriad.scheduler.constraints.Constraint) HashSet(java.util.HashSet)

Example 3 with ServiceConfiguration

use of org.apache.myriad.configuration.ServiceConfiguration in project incubator-myriad by apache.

the class ServiceTaskFactory method createTask.

@Override
public Protos.TaskInfo createTask(ResourceOfferContainer resourceOfferContainer, Protos.FrameworkID frameworkId, Protos.TaskID taskId, NodeTask nodeTask) {
    ServiceConfiguration serviceConfig = cfg.getServiceConfiguration(nodeTask.getTaskPrefix()).get();
    Objects.requireNonNull(serviceConfig, "ServiceConfig should be non-null");
    Objects.requireNonNull(serviceConfig.getCommand().orNull(), "command for ServiceConfig should be non-null");
    List<Protos.Resource> portResources = resourceOfferContainer.consumePorts(nodeTask.getProfile().getPorts().values());
    Protos.CommandInfo commandInfo = clGenerator.generateCommandLine(nodeTask.getProfile(), serviceConfig, rangesConverter(portResources));
    LOGGER.info("Command line for service: {} is: {}", commandInfo.getValue());
    Protos.TaskInfo.Builder taskBuilder = Protos.TaskInfo.newBuilder();
    taskBuilder.setName(nodeTask.getTaskPrefix()).setTaskId(taskId).setSlaveId(resourceOfferContainer.getSlaveId()).addAllResources(resourceOfferContainer.consumeCpus(nodeTask.getProfile().getCpus())).addAllResources(resourceOfferContainer.consumeMem(nodeTask.getProfile().getMemory())).addAllResources(portResources);
    taskBuilder.setCommand(commandInfo);
    if (cfg.getContainerInfo().isPresent()) {
        taskBuilder.setContainer(getContainerInfo());
    }
    return taskBuilder.build();
}
Also used : ServiceConfiguration(org.apache.myriad.configuration.ServiceConfiguration) Protos(org.apache.mesos.Protos)

Example 4 with ServiceConfiguration

use of org.apache.myriad.configuration.ServiceConfiguration in project incubator-myriad by apache.

the class TestServiceTaskFactory method testServiceTaskFactory.

@Test
public void testServiceTaskFactory() {
    ServiceCommandLineGenerator clGenerator = new ServiceCommandLineGenerator(cfgWithDocker);
    TaskUtils taskUtils = new TaskUtils(cfgWithDocker);
    Protos.Offer offer = new OfferBuilder("test.com").addScalarResource("cpus", 10.0).addScalarResource("mem", 16000).addRangeResource("ports", 3400, 3410).build();
    Map<String, ServiceConfiguration> stringServiceConfigurationMap = cfgWithDocker.getServiceConfigurations();
    System.out.print(stringServiceConfigurationMap);
    ServiceConfiguration serviceConfiguration = cfgWithDocker.getServiceConfigurations().get("jobhistory");
    ServiceResourceProfile profile = new ServiceResourceProfile("jobhistory", serviceConfiguration.getCpus(), serviceConfiguration.getJvmMaxMemoryMB(), serviceConfiguration.getPorts());
    NodeTask nodeTask = new NodeTask(profile, null);
    nodeTask.setTaskPrefix("jobhistory");
    ResourceOfferContainer roc = new ResourceOfferContainer(offer, profile, null);
    System.out.print(roc.getPorts());
    ServiceTaskFactory taskFactory = new ServiceTaskFactory(cfgWithDocker, taskUtils, clGenerator);
    Protos.TaskInfo taskInfo = taskFactory.createTask(roc, frameworkId, makeTaskId("jobhistory"), nodeTask);
    assertTrue("taskInfo should have a container", taskInfo.hasContainer());
    assertFalse("The container should not have an executor", taskInfo.hasExecutor());
    Protos.ContainerInfo containerInfo = taskInfo.getContainer();
    assertTrue("There should be two volumes", containerInfo.getVolumesCount() == 2);
    assertTrue("The first volume should be read only", containerInfo.getVolumes(0).getMode().equals(Protos.Volume.Mode.RO));
    assertTrue("The first volume should be read write", containerInfo.getVolumes(1).getMode().equals(Protos.Volume.Mode.RW));
    assertTrue("There should be a docker image", containerInfo.getDocker().hasImage());
    assertTrue("The docker image should be mesos/myraid", containerInfo.getDocker().getImage().equals("mesos/myriad"));
    assertTrue("Should be using host networking", containerInfo.getDocker().getNetwork().equals(Protos.ContainerInfo.DockerInfo.Network.HOST));
    assertTrue("There should be two parameters", containerInfo.getDocker().getParametersList().size() == 2);
    assertTrue("Privledged mode should be false", containerInfo.getDocker().getPrivileged() == false);
}
Also used : OfferBuilder(org.apache.myriad.scheduler.offer.OfferBuilder) NodeTask(org.apache.myriad.state.NodeTask) ResourceOfferContainer(org.apache.myriad.scheduler.resource.ResourceOfferContainer) ServiceConfiguration(org.apache.myriad.configuration.ServiceConfiguration) Protos(org.apache.mesos.Protos) Test(org.junit.Test) BaseConfigurableTest(org.apache.myriad.BaseConfigurableTest)

Example 5 with ServiceConfiguration

use of org.apache.myriad.configuration.ServiceConfiguration 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)

Aggregations

ServiceConfiguration (org.apache.myriad.configuration.ServiceConfiguration)6 Protos (org.apache.mesos.Protos)3 Map (java.util.Map)2 BaseConfigurableTest (org.apache.myriad.BaseConfigurableTest)2 MyriadConfiguration (org.apache.myriad.configuration.MyriadConfiguration)2 NodeTask (org.apache.myriad.state.NodeTask)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 CommandInfo (org.apache.mesos.Protos.CommandInfo)1 MyriadBadConfigurationException (org.apache.myriad.configuration.MyriadBadConfigurationException)1 NMTaskFactory (org.apache.myriad.scheduler.NMTaskFactory)1 ServiceProfileManager (org.apache.myriad.scheduler.ServiceProfileManager)1 ServiceResourceProfile (org.apache.myriad.scheduler.ServiceResourceProfile)1 ServiceTaskFactory (org.apache.myriad.scheduler.ServiceTaskFactory)1 TaskFactory (org.apache.myriad.scheduler.TaskFactory)1 Constraint (org.apache.myriad.scheduler.constraints.Constraint)1 LikeConstraint (org.apache.myriad.scheduler.constraints.LikeConstraint)1