Beispiel #1
0
  private static void handleCoordinateOperation() {
    final Resolver resolver = cloudname.getResolver();
    final Coordinate coordinate = Coordinate.parse(coordinateFlag);
    switch (operationFlag) {
      case CREATE:
        try {
          cloudname.createCoordinate(coordinate);
        } catch (CloudnameException e) {
          System.err.println("Got error: " + e.getMessage());
          break;
        } catch (CoordinateExistsException e) {
          e.printStackTrace();
          break;
        }
        System.err.println("Created coordinate.");
        break;
      case DELETE:
        try {
          cloudname.destroyCoordinate(coordinate);
        } catch (CoordinateDeletionException e) {
          System.err.println("Got error: " + e.getMessage());
          return;
        } catch (CoordinateMissingException e) {
          System.err.println("Got error: " + e.getMessage());
          break;
        } catch (CloudnameException e) {
          System.err.println("Got error: " + e.getMessage());
          break;
        }
        System.err.println("Deleted coordinate.");
        break;
      case STATUS:
        {
          ServiceStatus status;
          try {
            status = cloudname.getStatus(coordinate);
          } catch (CloudnameException e) {
            System.err.println(
                "Problems loading status, is service running? Error:\n" + e.getMessage());
            break;
          }
          System.err.println(
              "Status:\n" + status.getState().toString() + " " + status.getMessage());
          List<Endpoint> endpoints = null;
          try {
            endpoints =
                resolver.resolve(
                    "all."
                        + coordinate.getService()
                        + "."
                        + coordinate.getUser()
                        + "."
                        + coordinate.getCell());
          } catch (CloudnameException e) {
            System.err.println("Got error: " + e.getMessage());
            break;
          }
          System.err.println("Endpoints:");
          for (Endpoint endpoint : endpoints) {
            if (endpoint.getCoordinate().getInstance() == coordinate.getInstance()) {
              System.err.println(
                  endpoint.getName()
                      + "-->"
                      + endpoint.getHost()
                      + ":"
                      + endpoint.getPort()
                      + " protocol:"
                      + endpoint.getProtocol());
              System.err.println("Endpoint data:\n" + endpoint.getEndpointData());
            }
          }
          break;
        }
      case HOST:
        {
          List<Endpoint> endpoints = null;
          try {
            endpoints = resolver.resolve(coordinate.asString());
          } catch (CloudnameException e) {
            System.err.println(
                "Could not resolve " + coordinate.asString() + " Error:\n" + e.getMessage());
            break;
          }
          for (Endpoint endpoint : endpoints) {
            System.out.println("Host: " + endpoint.getHost());
          }
        }
        break;
      case SET_CONFIG:
        try {
          cloudname.setConfig(coordinate, configFlag, null);
        } catch (CloudnameException e) {
          System.err.println("Got error: " + e.getMessage());
          break;

        } catch (CoordinateMissingException e) {
          System.err.println("Non-existing coordinate.");
        }
        System.err.println("Config updated.");
        break;

      case READ_CONFIG:
        try {
          System.out.println("Config is:" + cloudname.getConfig(coordinate));
        } catch (CoordinateMissingException e) {
          System.err.println("Non-existing coordinate.");
        } catch (CloudnameException e) {
          System.err.println("Problem with cloudname: " + e.getMessage());
        }
        break;
      default:
        System.out.println("Unknown command " + operationFlag);
    }
  }