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);
}
}
}
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);
}
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();
}
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);
}
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));
}
}
Aggregations