MyriadOperations { public void flexUpAService(int instances, String serviceName) throws MyriadBadConfigurationException { final ServiceConfiguration auxTaskConf = cfg.getServiceConfiguration(serviceName).get(); if (auxTaskConf.getMaxInstances().isPresent()) { 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); } @Inject  MyriadOperations(MyriadConfiguration cfg, SchedulerState schedulerState,
      NodeScaleDownPolicy nodeScaleDownPolicy, MyriadDriverManager driverManager,
      MyriadWebServer myriadWebServer, RMContext rmContext); void flexUpCluster(ServiceResourceProfile serviceResourceProfile, int instances, Constraint constraint); void flexDownCluster(ServiceResourceProfile serviceResourceProfile, Constraint constraint, int numInstancesToScaleDown); void flexUpAService(int instances, String serviceName); void flexDownAService(int numInstancesToScaleDown, String serviceName); Integer getFlexibleInstances(String taskPrefix); void shutdownFramework();  }
@Test(expected = MyriadBadConfigurationException.class) public void testFlexUpAServiceOverMaxInstances() throws Exception { MyriadOperations ops = initialize(); ops.flexUpAService(3, "jobhistory"); }