示例#1
0
  /**
   * Creates a the rrd file from the rrdDefinition. Since this definition is really just the create
   * command string it just executes it.
   *
   * @param createCommand a {@link java.lang.String} object.
   * @throws java.lang.Exception if any.
   */
  @Override
  public void createFile(CreateCommand createCommand, Map<String, String> attributeMappings)
      throws Exception {
    if (createCommand == null) {
      LOG.debug("createRRD: skipping RRD file");
      return;
    }
    LOG.debug("Executing: rrdtool {}", createCommand.toString());
    Interface.launch(createCommand.toString());

    String filenameWithoutExtension = createCommand.filename.replace(RrdUtils.getExtension(), "");
    int lastIndexOfSeparator = filenameWithoutExtension.lastIndexOf(File.separator);

    RrdUtils.createMetaDataFile(
        filenameWithoutExtension.substring(0, lastIndexOfSeparator),
        filenameWithoutExtension.substring(lastIndexOfSeparator),
        attributeMappings);
  }
  public void registerCommands(Object register) {
    for (Method method : register.getClass().getMethods()) {
      CreateCommand anote = method.getAnnotation(CreateCommand.class);

      if (anote != null) {

        if (anote.names().length == 0) {
          plugin.logger.info("Creator has found an unnamed command");
          continue;
        }

        Command command = new Command(this.plugin, anote, register, method);

        leastCommands.add(command);

        for (String name : anote.names()) {
          commands.put(name, command);
        }
      }
    }
  }
示例#3
0
  public void createCommand(String query) {

    int tableExists = -1;
    Parser sqlP = new Parser();
    int invalidQuery = sqlP.ParseQuery(query);

    CreateCommand createInfo;
    createInfo = sqlP.getcreateInfo();

    Iterator<Table> it = Tables.iterator();

    if (invalidQuery == 1) {
      while (it.hasNext()) {
        if (it.next().getTableName().equals(createInfo.getTableName())) {
          tableExists = 1;
        }
      }

      if (tableExists == -1) {

        File csvFile = new File(pathForData + createInfo.getTableName() + ".csv");
        File dataFile = new File(pathForData + createInfo.getTableName() + ".data");
        File configFile = new File("/tmp/config.txt");

        try {
          BufferedWriter csvOutput = new BufferedWriter(new FileWriter(csvFile));
          BufferedWriter dataOutput = new BufferedWriter(new FileWriter(dataFile));
          PrintWriter configOutput =
              new PrintWriter(new BufferedWriter(new FileWriter(configFile, true)));

          configOutput.println("BEGIN");
          System.out.println("QueryType:create");
          System.out.println("Tablename:" + createInfo.getTableName());
          configOutput.println(createInfo.getTableName());

          ArrayList<Attribute> attributeList = createInfo.getAttributeList();
          System.out.print("Attribute:");

          for (int i = 0; i < (attributeList.size() - 1); i++) {
            Attribute A = attributeList.get(i);
            System.out.print(A.getName() + " " + A.getDataType() + ",");
            configOutput.println(A.getName() + ", " + A.getDataType());
            dataOutput.write(A.getName() + ":" + A.getDataType() + ",");
          }
          Attribute A = attributeList.get(attributeList.size() - 1);
          System.out.println(A.getName() + " " + A.getDataType());
          configOutput.println(A.getName() + ", " + A.getDataType());
          dataOutput.write(A.getName() + ":" + A.getDataType());
          configOutput.println("END");

          configOutput.close();
          csvOutput.close();
          dataOutput.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } else {
        System.out.println("Query Invalid");
      }
    }
  }