public void flexUpAService()

in myriad-scheduler/src/main/java/org/apache/myriad/scheduler/MyriadOperations.java [121:151]


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