Beispiel #1
0
  @ScriptUsage(
      description = "create a module instance",
      arguments = {
        @ScriptArgument(name = "module type", type = "string", description = "module type "),
        @ScriptArgument(name = "factory name", type = "string", description = "factory name"),
        @ScriptArgument(name = "instance name", type = "string", description = "instance name")
      })
  public void createInstance(String[] args) {
    RadiusModuleType type = RadiusModuleType.parse(args[0]);
    if (type == null) {
      context.println("unknown module type");
      return;
    }

    String factoryName = args[1];
    String instanceName = args[2];

    RadiusModule module = server.getModule(type);
    RadiusFactory<?> factory = module.getFactory(factoryName);
    if (factory == null) {
      context.println("factory not found");
      return;
    }

    try {
      Map<String, Object> configs = config(factory.getConfigMetadatas());
      RadiusInstance instance = module.createInstance(instanceName, factoryName, configs);
      context.println("created " + instance);
    } catch (InterruptedException e) {
      context.println("");
      context.println("interrupted");
    } catch (Throwable t) {
      context.println(t.getMessage());
    }
  }
Beispiel #2
0
  private List<String> select(RadiusModuleType type) throws InterruptedException {
    // get instance names
    List<String> names = new ArrayList<String>();
    RadiusModule module = server.getModule(type);
    for (RadiusInstance instance : module.getInstances()) {
      names.add(instance.getName());
    }

    // print instance list
    List<String> selected = new ArrayList<String>();

    int i = 1;
    for (String name : names) {
      context.println("[" + (i++) + "] " + name);
    }
    context.println("---------------------------");

    while (true) {
      try {
        context.print("select index (0 for end): ");
        int index = Integer.valueOf(context.readLine());
        if (index == 0) break;

        if (index < 0 || index > names.size()) {
          context.println("no item corresponds to selected index");
          continue;
        }

        // add to select bucket
        String name = names.get(index - 1);
        if (!selected.contains(name)) {
          selected.add(name);
          context.println(name + " added");
        }

      } catch (NumberFormatException e) {
        context.println("");
        throw new RuntimeException("invalid number format");
      }
    }

    return selected;
  }
Beispiel #3
0
  @ScriptUsage(
      description = "list all module instances",
      arguments = {
        @ScriptArgument(name = "module type", type = "string", description = "module type ")
      })
  public void instances(String[] args) {
    context.println("Instances");
    context.println("------------");

    RadiusModuleType type = RadiusModuleType.parse(args[0]);
    if (type == null) {
      context.println("unknown module type");
      return;
    }

    RadiusModule module = server.getModule(type);

    for (RadiusInstance instance : module.getInstances()) {
      context.println("[" + instance.getName() + "] " + instance);
    }
  }
Beispiel #4
0
  @ScriptUsage(
      description = "remove module instance",
      arguments = {
        @ScriptArgument(name = "module type", type = "string", description = "module type"),
        @ScriptArgument(name = "instance name", type = "string", description = "instance name")
      })
  public void removeInstance(String[] args) {
    RadiusModuleType type = RadiusModuleType.parse(args[0]);
    if (type == null) {
      context.println("unknown module type");
      return;
    }

    String instanceName = args[1];

    try {
      RadiusModule module = server.getModule(type);
      module.removeInstance(instanceName);
      context.println("removed");
    } catch (Exception e) {
      context.println(e.getMessage());
    }
  }