Example #1
0
  protected void run(OperationHandler handler) {
    boolean isStartReconnectionTimer = true;
    long start_time = System.currentTimeMillis();
    long interval_time = start_time;
    long reconnection_throughput_time = 0;
    long interval_ops = 0;
    while (((_opcount == 0) || (_opsdone < _opcount)) && !_workload.isStopRequested()) {
      long current_time = System.currentTimeMillis();
      if (current_time - interval_time > CHECK_THROUGHPUT_INTERVAL) {
        // reconnect to the database if low throughput
        double throughput = interval_ops / ((double) current_time - interval_time);
        if (throughput < reconnectionthroughput) {
          if (isStartReconnectionTimer) {
            reconnection_throughput_time = System.currentTimeMillis();
            isStartReconnectionTimer = false;
          } else {
            if (current_time - reconnection_throughput_time > reconncetiontime) {
              try {
                System.out.println("Reconnecting to the DB...");
                _db.reinit();
                reconnectioncounter++;
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          }
        } else {
          isStartReconnectionTimer = true;
        }
        interval_time = current_time;
        interval_ops = 0;
      }

      if (!handler.doOperation(_db, _workloadstate)) {
        break;
      }

      interval_ops++;
      _opsdone++;

      // throttle the operations
      if (_target > 0) {
        // this is more accurate than other throttling approaches we have tried,
        // like sleeping for (1/target throughput)-operation latency,
        // because it smooths timing inaccuracies (from sleep() taking an int,
        // current time in millis) over many operations
        // while (System.currentTimeMillis() - interval_time < (interval_ops / _target)) {
        while (_target < interval_ops / ((double) System.currentTimeMillis() - interval_time)) {
          try {
            sleep(1);
          } catch (InterruptedException e) {
            // do nothing.
          }
        }
      }
      runtime = System.currentTimeMillis() - start_time;
    }
  }
Example #2
0
  public void run() {
    try {
      _db.init();
    } catch (DBException e) {
      // TODO make error logging level configurable
      e.printStackTrace();
      return;
    }

    try {
      _workloadstate = _workload.initThread(_props);
    } catch (WorkloadException e) {
      e.printStackTrace();
      return;
    }

    // spread the thread operations out so they don't all hit the DB at the same time
    try {
      // GH issue 4 - throws exception if _target>1 because random.nextInt argument must be >0
      // and the sleep() doesn't make sense for granularities < 1 ms anyway
      if ((_target > 0) && (_target <= 1.0)) {
        sleep(Utils.random().nextInt((int) (1.0 / _target)));
      }
    } catch (InterruptedException e) {
      // do nothing.
    }

    try {
      if (_dotransactions) {
        run(
            new OperationHandler() {
              @Override
              public boolean doOperation(DB db, Object workloadstate) {
                return _workload.doTransaction(db, workloadstate);
              }
            });
      } else {
        run(
            new OperationHandler() {
              @Override
              public boolean doOperation(DB db, Object workloadstate) {
                return _workload.doInsert(db, workloadstate);
              }
            });
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      _db.cleanup();
    } catch (DBException e) {
      e.printStackTrace();
    }
  }
  public void initDB(String[] args) {

    final String servers = Args.valueOf(args, "-servers", "localhost");

    String propFile = Args.valueOf(args, "-props", "swiftsocial-test.props");
    Properties properties = Props.parseFile("swiftsocial", propFile);
    configBloatedCounters(properties);
    SafeLog.configure(properties);

    System.err.println("Populating db with users...");

    int numUsers = Props.intValue(properties, "swiftsocial.numUsers", 1000);

    final int NumUsers = Args.valueOf(args, "-users", numUsers);
    Workload.generateUsers(NumUsers);

    int threads = Args.valueOf(args, "-threads", 6);
    final int PARTITION_SIZE = 1000;
    int partitions = numUsers / PARTITION_SIZE + (numUsers % PARTITION_SIZE > 0 ? 1 : 0);
    ExecutorService pool = Executors.newFixedThreadPool(threads);

    final AtomicInteger counter = new AtomicInteger(0);
    for (int i = 0; i < partitions; i++) {
      int lo = i * PARTITION_SIZE, hi = (i + 1) * PARTITION_SIZE;
      final List<String> partition = Workload.getUserData().subList(lo, Math.min(hi, numUsers));
      pool.execute(
          new Runnable() {
            public void run() {
              SwiftOptions options = new SwiftOptions(servers, DCConstants.SURROGATE_PORT);
              options.setCacheUpdateProtocol(CacheUpdateProtocol.NO_CACHE_OR_UNCOORDINATED);
              SwiftSocialBenchmark.super.initUsers(options, partition, counter, NumUsers);
            }
          });
    }
    Threading.awaitTermination(pool, Integer.MAX_VALUE);
    Threading.sleep(5000);
    System.err.println("\nFinished populating db with users.");
  }
 public static void main(String[] args) {
   Workload w = new Workload();
   w.active = true;
   w.consumerGroup = "group1";
   w.maxWorkers = 4;
   w.messageHandlerName = "com.jointhegrid.ironcount.mockingbird.MockingBirdMessageHandler";
   w.name = "testworkload";
   w.properties = new HashMap<String, String>();
   w.properties.put("aprop", "avalue");
   w.topic = "topic1";
   w.zkConnect = "localhost:8888";
   ObjectMapper map = new ObjectMapper();
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   try {
     map.writeValue(baos, w);
   } catch (IOException ex) {
     System.out.println(ex);
   }
   System.out.println(baos.toString());
 }
Example #5
0
 public void addWorkload(
     Long periodNumber, Double workload, Double spent, Integer lastWorkedStep) {
   Workload newWorkload = new Workload();
   newWorkload.setPeriodNumber(periodNumber);
   newWorkload.setWorkload(workload);
   newWorkload.setSpentWorkload(spent);
   newWorkload.setLastWorkedStep(lastWorkedStep);
   newWorkload.setIteration(this);
   this.workloads.add(newWorkload);
 }
  @SuppressWarnings("unchecked")
  public boolean parseOptions(String args[]) {

    Options options = new Options();
    options.addOption(OUTPUT_DIR_OPTION, true, "Output directory" + Workload.MERGE.onlyUsedFor());
    options.addOption(
        COMPRESSION_OPTION,
        true,
        " Compression type, one of "
            + Arrays.toString(Compression.Algorithm.values())
            + Workload.MERGE.onlyUsedFor());
    options.addOption(
        BLOOM_FILTER_OPTION,
        true,
        "Bloom filter type, one of "
            + Arrays.toString(StoreFile.BloomType.values())
            + Workload.MERGE.onlyUsedFor());
    options.addOption(BLOCK_SIZE_OPTION, true, "HFile block size" + Workload.MERGE.onlyUsedFor());
    options.addOption(
        DURATION_OPTION,
        true,
        "The amount of time to run the "
            + "random read workload for"
            + Workload.RANDOM_READS.onlyUsedFor());
    options.addOption(
        NUM_THREADS_OPTION,
        true,
        "The number of random " + "reader threads" + Workload.RANDOM_READS.onlyUsedFor());
    options.addOption(
        NUM_THREADS_OPTION,
        true,
        "The number of random " + "reader threads" + Workload.RANDOM_READS.onlyUsedFor());
    options.addOption(
        LoadTestTool.OPT_DATA_BLOCK_ENCODING, true, LoadTestTool.OPT_DATA_BLOCK_ENCODING_USAGE);
    options.addOption(
        LoadTestTool.OPT_ENCODE_IN_CACHE_ONLY, false, LoadTestTool.OPT_ENCODE_IN_CACHE_ONLY_USAGE);
    options.addOptionGroup(Workload.getOptionGroup());

    if (args.length == 0) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp(HFileReadWriteTest.class.getSimpleName(), options, true);
      return false;
    }

    CommandLineParser parser = new PosixParser();
    CommandLine cmdLine;
    try {
      cmdLine = parser.parse(options, args);
    } catch (ParseException ex) {
      LOG.error(ex);
      return false;
    }

    workload = Workload.fromCmdLine(cmdLine);
    if (workload == null) return false;

    inputFileNames = (List<String>) cmdLine.getArgList();

    if (inputFileNames.size() == 0) {
      LOG.error("No input file names specified");
      return false;
    }

    if (inputFileNames.size() < workload.minNumInputFiles) {
      LOG.error("Too few input files: at least " + workload.minNumInputFiles + " required");
      return false;
    }

    if (inputFileNames.size() > workload.maxNumInputFiles) {
      LOG.error("Too many input files: at most " + workload.minNumInputFiles + " allowed");
      return false;
    }

    if (cmdLine.hasOption(COMPRESSION_OPTION)) {
      compression = Compression.Algorithm.valueOf(cmdLine.getOptionValue(COMPRESSION_OPTION));
    }

    if (cmdLine.hasOption(BLOOM_FILTER_OPTION)) {
      bloomType = StoreFile.BloomType.valueOf(cmdLine.getOptionValue(BLOOM_FILTER_OPTION));
    }

    encodeInCacheOnly = cmdLine.hasOption(LoadTestTool.OPT_ENCODE_IN_CACHE_ONLY);

    if (cmdLine.hasOption(LoadTestTool.OPT_DATA_BLOCK_ENCODING)) {
      dataBlockEncoding =
          DataBlockEncoding.valueOf(cmdLine.getOptionValue(LoadTestTool.OPT_DATA_BLOCK_ENCODING));
      // Optionally encode on disk, always encode in cache.
      dataBlockEncoder =
          new HFileDataBlockEncoderImpl(
              encodeInCacheOnly ? DataBlockEncoding.NONE : dataBlockEncoding, dataBlockEncoding);
    } else {
      if (encodeInCacheOnly) {
        LOG.error(
            "The -"
                + LoadTestTool.OPT_ENCODE_IN_CACHE_ONLY
                + " option does not make sense without -"
                + LoadTestTool.OPT_DATA_BLOCK_ENCODING);
        return false;
      }
    }

    blockSize = conf.getInt("hfile.min.blocksize.size", 65536);
    if (cmdLine.hasOption(BLOCK_SIZE_OPTION))
      blockSize = Integer.valueOf(cmdLine.getOptionValue(BLOCK_SIZE_OPTION));

    if (workload == Workload.MERGE) {
      String outputDirStr = cmdLine.getOptionValue(OUTPUT_DIR_OPTION);
      if (outputDirStr == null) {
        LOG.error("Output directory is not specified");
        return false;
      }
      outputDir = new Path(outputDirStr);
      // Will be checked for existence in validateConfiguration.
    }

    if (workload == Workload.RANDOM_READS) {
      if (!requireOptions(cmdLine, new String[] {DURATION_OPTION, NUM_THREADS_OPTION})) {
        return false;
      }

      durationSec = Integer.parseInt(cmdLine.getOptionValue(DURATION_OPTION));
      numReadThreads = Integer.parseInt(cmdLine.getOptionValue(NUM_THREADS_OPTION));
    }

    Collections.sort(inputFileNames);

    return true;
  }
Example #7
0
  @SuppressWarnings("unchecked")
  public static void main(String[] args) throws FileNotFoundException {
    String dbname;
    Properties props = new Properties();
    Properties fileprops = new Properties();
    boolean dotransactions = true;
    int threadcount = 1;
    int target = 0;
    boolean status = false;
    String label = "";

    // parse arguments
    int argindex = 0;

    if (args.length == 0) {
      usageMessage();
      System.exit(0);
    }

    while (args[argindex].startsWith("-")) {
      if (args[argindex].compareTo("-threads") == 0) {
        argindex++;
        if (argindex >= args.length) {
          usageMessage();
          System.exit(0);
        }
        int tcount = Integer.parseInt(args[argindex]);
        props.setProperty("threadcount", tcount + "");
        argindex++;
      } else if (args[argindex].compareTo("-target") == 0) {
        argindex++;
        if (argindex >= args.length) {
          usageMessage();
          System.exit(0);
        }
        int ttarget = Integer.parseInt(args[argindex]);
        props.setProperty("target", ttarget + "");
        argindex++;
      } else if (args[argindex].compareTo("-load") == 0) {
        dotransactions = false;
        argindex++;
      } else if (args[argindex].compareTo("-t") == 0) {
        dotransactions = true;
        argindex++;
      } else if (args[argindex].compareTo("-s") == 0) {
        status = true;
        argindex++;
      } else if (args[argindex].compareTo("-db") == 0) {
        argindex++;
        if (argindex >= args.length) {
          usageMessage();
          System.exit(0);
        }
        props.setProperty("db", args[argindex]);
        argindex++;
      } else if (args[argindex].compareTo("-l") == 0) {
        argindex++;
        if (argindex >= args.length) {
          usageMessage();
          System.exit(0);
        }
        label = args[argindex];
        argindex++;
      } else if (args[argindex].compareTo("-P") == 0) {
        argindex++;
        if (argindex >= args.length) {
          usageMessage();
          System.exit(0);
        }
        String propfile = args[argindex];
        argindex++;

        Properties myfileprops = new Properties();
        try {
          myfileprops.load(new FileInputStream(propfile));
        } catch (IOException e) {
          e.printStackTrace();
          System.exit(0);
        }

        // Issue #5 - remove call to stringPropertyNames to make compilable under Java 1.5
        for (Enumeration e = myfileprops.propertyNames(); e.hasMoreElements(); ) {
          String prop = (String) e.nextElement();

          fileprops.setProperty(prop, myfileprops.getProperty(prop));
        }

      } else if (args[argindex].compareTo("-p") == 0) {
        argindex++;
        if (argindex >= args.length) {
          usageMessage();
          System.exit(0);
        }
        int eq = args[argindex].indexOf('=');
        if (eq < 0) {
          usageMessage();
          System.exit(0);
        }

        String name = args[argindex].substring(0, eq);
        String value = args[argindex].substring(eq + 1);
        props.put(name, value);
        // System.out.println("["+name+"]=["+value+"]");
        argindex++;
      } else {
        System.out.println("Unknown option " + args[argindex]);
        usageMessage();
        System.exit(0);
      }

      if (argindex >= args.length) {
        break;
      }
    }

    if (argindex != args.length) {
      usageMessage();
      System.exit(0);
    }

    // set up logging
    // BasicConfigurator.configure();

    // overwrite file properties with properties from the command line

    // Issue #5 - remove call to stringPropertyNames to make compilable under Java 1.5
    for (Enumeration e = props.propertyNames(); e.hasMoreElements(); ) {
      String prop = (String) e.nextElement();
      fileprops.setProperty(prop, props.getProperty(prop));
    }

    props = fileprops;

    if (!checkRequiredProperties(props)) {
      System.exit(0);
    }

    long maxExecutionTime = Integer.parseInt(props.getProperty(MAX_EXECUTION_TIME, "0"));

    // get number of threads, target and db
    threadcount = Integer.parseInt(props.getProperty("threadcount", "1"));
    dbname = props.getProperty("db", "com.yahoo.ycsb.BasicDB");
    target = Integer.parseInt(props.getProperty("target", "0"));

    // compute the target throughput
    double targetperthreadperms = -1;
    if (target > 0) {
      double targetperthread = ((double) target) / ((double) threadcount);
      targetperthreadperms = targetperthread / 1000.0;
    }

    System.out.println("YCSB Client 0.1");
    System.out.print("Command line:");
    for (int i = 0; i < args.length; i++) {
      System.out.print(" " + args[i]);
    }
    System.out.println();
    System.err.println("Loading workload...");

    // show a warning message that creating the workload is taking a while
    // but only do so if it is taking longer than 2 seconds
    // (showing the message right away if the setup wasn't taking very long was confusing people)
    Thread warningthread =
        new Thread() {
          public void run() {
            try {
              sleep(2000);
            } catch (InterruptedException e) {
              return;
            }
            System.err.println(" (might take a few minutes for large data sets)");
          }
        };

    warningthread.start();

    // set up measurements
    Measurements.setProperties(props);

    // load the workload
    ClassLoader classLoader = Client.class.getClassLoader();

    Workload workload = null;

    try {
      Class workloadclass =
          classLoader.loadClass(
              props.getProperty(WORKLOAD_PROPERTY, "com.yahoo.ycsb.workloads.CoreWorkload"));
      workload = (Workload) workloadclass.newInstance();
    } catch (Exception e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
      System.exit(0);
    }

    try {
      workload.init(props);
    } catch (WorkloadException e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
      System.exit(0);
    }

    warningthread.interrupt();

    // run the workload

    System.err.println("Starting test.");

    int opcount;
    if (dotransactions) {
      opcount = Integer.parseInt(props.getProperty(OPERATION_COUNT_PROPERTY, "0"));
    } else {
      if (props.containsKey(INSERT_COUNT_PROPERTY)) {
        opcount = Integer.parseInt(props.getProperty(INSERT_COUNT_PROPERTY, "0"));
      } else {
        opcount = Integer.parseInt(props.getProperty(RECORD_COUNT_PROPERTY, "0"));
      }
    }

    int warmupopcount = Integer.parseInt(props.getProperty(WARMUP_OPERATION_COUNT_PROPERTY, "0"));
    int warmupexectime = Integer.parseInt(props.getProperty(WARMUP_EXECUTION_TIME, "0"));

    if (dotransactions) {
      Vector<Thread> warmupThreads = new Vector<Thread>();
      for (int threadid = 0; threadid < threadcount; threadid++) {
        DB db = null;
        try {
          db = DBFactory.rawDB(dbname, props);
        } catch (UnknownDBException e) {
          System.out.println("Unknown DB " + dbname);
          System.exit(0);
        }
        Thread t =
            new WarmupThread(
                db,
                dotransactions,
                workload,
                props,
                warmupopcount / threadcount,
                targetperthreadperms,
                warmupexectime);
        warmupThreads.add(t);
      }

      for (Thread t : warmupThreads) {
        t.start();
      }

      for (Thread t : warmupThreads) {
        try {
          t.join();
        } catch (InterruptedException e) {

        }
      }
    }

    Vector<Thread> threads = new Vector<Thread>();

    for (int threadid = 0; threadid < threadcount; threadid++) {
      DB db = null;
      try {
        db = DBFactory.wrappedDB(dbname, props);
      } catch (UnknownDBException e) {
        System.out.println("Unknown DB " + dbname);
        System.exit(0);
      }

      // spread the ops out across threads evenly, but add the remainder after dividing to thread
      // zero
      int opsPerThread = opcount / threadcount;
      int threadOps =
          threadid == 0 ? opsPerThread + (opcount - opsPerThread * threadcount) : opsPerThread;
      Thread t =
          new ClientThread(db, dotransactions, workload, props, threadOps, targetperthreadperms);
      threads.add(t);
    }

    StatusThread statusthread = null;

    if (status) {
      boolean standardstatus = false;
      if (props.getProperty("measurementtype", "").compareTo("timeseries") == 0) {
        standardstatus = true;
      }
      statusthread = new StatusThread(threads, label, standardstatus);
      statusthread.start();
    }

    MeasurementsExporter exporter = getExporter(props);

    long exportmeasurementsinterval =
        Long.parseLong(props.getProperty(EXPORT_MEASUREMENTS_INTERVAL, "1000"));

    final ExportMeasurementsThread exportmeasurementsthread =
        new ExportMeasurementsThread(threads, exporter, exportmeasurementsinterval);
    exportmeasurementsthread.start();

    // add hook to export measurements on shutdown
    Thread hook =
        new Thread() {
          public void run() {
            exportmeasurementsthread.exportOverall();
          }
        };
    Runtime.getRuntime().addShutdownHook(hook);

    // start client threads
    for (Thread t : threads) {
      t.start();
    }

    Thread terminator = null;

    if (maxExecutionTime > 0) {
      terminator = new TerminatorThread(maxExecutionTime, threads, workload);
      terminator.start();
    }

    long st = System.currentTimeMillis();
    int opsDone = 0;

    for (Thread t : threads) {
      try {
        t.join();
        opsDone += ((ClientThread) t).getOpsDone();
      } catch (InterruptedException e) {
      }
    }

    long en = System.currentTimeMillis();

    if (terminator != null && !terminator.isInterrupted()) {
      terminator.interrupt();
    }

    if (status) {
      statusthread.interrupt();
    }

    try {
      exportmeasurementsthread.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
    }

    try {
      workload.cleanup();
    } catch (WorkloadException e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
      System.exit(0);
    }

    // try
    // {
    //	exportMeasurements(exporter, opsDone, en - st);
    // } catch (IOException e)
    // {
    //	System.err.println("Could not export measurements, error: " + e.getMessage());
    //	e.printStackTrace();
    //	System.exit(-1);
    // }

    System.exit(0);
  }
Example #8
0
  public void run() {
    try {
      _db.init();
    } catch (DBException e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
      return;
    }

    try {
      _workloadstate = _workload.initThread(_props, _threadid, _threadcount);
    } catch (WorkloadException e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
      return;
    }

    // spread the thread operations out so they don't all hit the DB at the same time
    try {
      // GH issue 4 - throws exception if _target>1 because random.nextInt argument must be >0
      // and the sleep() doesn't make sense for granularities < 1 ms anyway
      if ((_target > 0) && (_target <= 1.0)) {
        sleep(Utils.random().nextInt((int) (1.0 / _target)));
      }
    } catch (InterruptedException e) {
      // do nothing.
    }

    try {
      if (_dotransactions) {
        long st = System.currentTimeMillis();

        while (((_opcount == 0) || (_opsdone < _opcount)) && !_workload.isStopRequested()) {

          if (!_workload.doTransaction(_db, _workloadstate)) {
            break;
          }

          _opsdone++;

          // throttle the operations
          if (_target > 0) {
            // this is more accurate than other throttling approaches we have tried,
            // like sleeping for (1/target throughput)-operation latency,
            // because it smooths timing inaccuracies (from sleep() taking an int,
            // current time in millis) over many operations
            while (System.currentTimeMillis() - st < ((double) _opsdone) / _target) {
              try {
                sleep(1);
              } catch (InterruptedException e) {
                // do nothing.
              }
            }
          }
        }
      } else {
        long st = System.currentTimeMillis();

        while (((_opcount == 0) || (_opsdone < _opcount)) && !_workload.isStopRequested()) {

          if (!_workload.doInsert(_db, _workloadstate)) {
            break;
          }

          _opsdone++;

          // throttle the operations
          if (_target > 0) {
            // this is more accurate than other throttling approaches we have tried,
            // like sleeping for (1/target throughput)-operation latency,
            // because it smooths timing inaccuracies (from sleep() taking an int,
            // current time in millis) over many operations
            while (System.currentTimeMillis() - st < ((double) _opsdone) / _target) {
              try {
                sleep(1);
              } catch (InterruptedException e) {
                // do nothing.
              }
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
      System.exit(0);
    }

    try {
      _db.cleanup();
    } catch (DBException e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
      return;
    }
  }
Example #9
0
  public static ProjectDTO getProjectByName(String name) {
    Project p;
    p = ProxyManager.getProjectProxy().findProjectByName(name);
    if (p != null) {
      ProjectDTO projectDTO = new ProjectDTO();
      projectDTO.setProjectId(p.getProjectId());
      projectDTO.setName(p.getName());
      projectDTO.setDescription(p.getDescription());
      projectDTO.setStatus(p.getStatus());
      Team team = p.getTeamTeamId();
      if (team != null) {
        TeamDTO teamDTO = new TeamDTO();
        teamDTO.setTeamId(team.getTeamId());
        teamDTO.setProductOwnerId(team.getProductOwnerId());
        teamDTO.setScrumMasterId(team.getScrumMasterId());
        ArrayList<UserDTO> userDTOList = new ArrayList<UserDTO>();
        for (User user : team.getUserList()) {
          UserDTO userDTO = new UserDTO();
          userDTO.setUserId(user.getUserId());
          userDTO.setUsername(user.getUsername());
          userDTO.setPassword(user.getPassword());
          userDTO.setFirstName(user.getFirstName());
          userDTO.setLastName(user.getLastName());
          userDTO.setEmail(user.getEmail());
          userDTO.setAdmin(user.getIsAdmin());
          userDTO.setSalt(user.getSalt());
          userDTO.setActive(user.getIsActive());
          userDTO.setTimeCreated(user.getTimeCreated());
          userDTOList.add(userDTO);
        }
        teamDTO.setUserList(userDTOList);
        projectDTO.setTeamTeamId(teamDTO);
      } else projectDTO.setTeamTeamId(null);

      List<SprintDTO> sprintDTOList = new ArrayList<SprintDTO>();
      if (p.getSprintList() != null) {
        for (Sprint s : p.getSprintList()) {
          s = ProxyManager.getSprintProxy().findSprint(s.getSprintPK());
          SprintDTO sprintDTO = new SprintDTO();
          SprintPKDTO sprintPKDTO = new SprintPKDTO();
          sprintPKDTO.setSprintId(s.getSprintPK().getSprintId());
          sprintPKDTO.setProjectProjectId(s.getSprintPK().getProjectProjectId());
          sprintDTO.setSprintPK(sprintPKDTO);
          sprintDTO.setSeqNumber(s.getSeqNumber());
          sprintDTO.setStatus(s.getStatus());
          sprintDTO.setStartDate(s.getStartDate());
          sprintDTO.setEndDate(s.getEndDate());
          sprintDTO.setVelocity(s.getVelocity());
          if (s.getUserStoryList() != null) {
            List<UserStoryDTO> userStoryDTOList = new ArrayList<UserStoryDTO>();
            for (UserStory userStory : s.getUserStoryList()) {
              userStory = ProxyManager.getUserStoryProxy().findUserStory(userStory.getStoryId());
              UserStoryDTO userStoryDTO = new UserStoryDTO();
              userStoryDTO.setStoryId(userStory.getStoryId());
              userStoryDTO.setName(userStory.getName());
              userStoryDTO.setContent(userStory.getContent());
              userStoryDTO.setBusinessValue(userStory.getBusinessValue());
              userStoryDTO.setStatus(userStory.getStatus());
              if (userStory.getEstimateTime() != null) {
                userStoryDTO.setEstimateTime(userStory.getEstimateTime().doubleValue());
              } else userStoryDTO.setEstimateTime(null);
              userStoryDTO.setStoryId(userStory.getStoryId());
              userStoryDTO.setProjectProjectId(projectDTO);
              userStoryDTO.setComment(userStory.getComment());
              userStoryDTO.setSprint(sprintDTO);

              PriorityDTO priorityDTO = new PriorityDTO();
              priorityDTO.setPriorityId(userStory.getPriorityPriorityId().getPriorityId());
              priorityDTO.setName(userStory.getPriorityPriorityId().getName());
              userStoryDTO.setPriorityPriorityId(priorityDTO);

              List<AcceptanceTestDTO> acceptanceTestDTOList = new ArrayList<AcceptanceTestDTO>();
              for (AcceptanceTest at : userStory.getAcceptanceTestList()) {
                AcceptanceTestDTO acceptanceTestDTO = new AcceptanceTestDTO();
                acceptanceTestDTO.setAcceptanceTestId(at.getAcceptanceTestId());
                acceptanceTestDTO.setContent(at.getContent());
                acceptanceTestDTOList.add(acceptanceTestDTO);
              }
              userStoryDTO.setAcceptanceTestList(acceptanceTestDTOList);

              if (userStory.getTaskList() != null) {
                List<TaskDTO> taskDTOList = new ArrayList<TaskDTO>();
                for (Task task : userStory.getTaskList()) {
                  task = ProxyManager.getTaskProxy().findTask(task.getTaskPK());
                  TaskDTO taskDTO = new TaskDTO();
                  taskDTO.setDescription(task.getDescription());
                  taskDTO.setTimeRemaining(task.getTimeRemaining());
                  taskDTO.setEstimatedTime(task.getEstimatedTime());
                  taskDTO.setStatus(task.getStatus());
                  taskDTO.setPreassignedUserName(task.getPreassignedUserName());
                  taskDTO.setAssignedDate(task.getAssignedDate());

                  taskDTO.setUserStory(userStoryDTO);

                  TaskPKDTO taskPKDTO = new TaskPKDTO();
                  taskPKDTO.setTaskId(task.getTaskPK().getTaskId());
                  taskPKDTO.setUserStoryStoryId(task.getTaskPK().getUserStoryStoryId());
                  taskDTO.setTaskPK(taskPKDTO);

                  if (task.getUserUserId() != null) {
                    User user =
                        ProxyManager.getUserProxy().findUser(task.getUserUserId().getUserId());
                    UserDTO userDTO = new UserDTO();
                    userDTO.setUserId(user.getUserId());
                    userDTO.setUsername(user.getUsername());
                    userDTO.setPassword(user.getPassword());
                    userDTO.setFirstName(user.getFirstName());
                    userDTO.setLastName(user.getLastName());
                    userDTO.setEmail(user.getEmail());
                    userDTO.setAdmin(user.getIsAdmin());
                    userDTO.setSalt(user.getSalt());
                    userDTO.setActive(user.getIsActive());
                    userDTO.setTimeCreated(user.getTimeCreated());
                    taskDTO.setUserUserId(userDTO);
                  }

                  List<WorkloadDTO> workloadDTOList = new ArrayList<WorkloadDTO>();
                  for (Workload workload : task.getWorkloadList()) {
                    workload =
                        ProxyManager.getWorkloadProxy().findWorkload(workload.getWorkloadPK());
                    WorkloadDTO workloadDTO = new WorkloadDTO();
                    workloadDTO.setDay(workload.getDay());
                    workloadDTO.setTimeRemaining(workload.getTimeRemaining());
                    workloadDTO.setTimeSpent(workload.getTimeSpent());
                    workloadDTO.setStarted(workload.getStarted());
                    workloadDTO.setStartTime(workload.getStartTime());
                    workloadDTO.setStopTime(workload.getStopTime());

                    User user =
                        ProxyManager.getUserProxy().findUser(workload.getUser().getUserId());
                    UserDTO userDTO = new UserDTO();
                    userDTO.setUserId(user.getUserId());
                    userDTO.setUsername(user.getUsername());
                    userDTO.setPassword(user.getPassword());
                    userDTO.setFirstName(user.getFirstName());
                    userDTO.setLastName(user.getLastName());
                    userDTO.setEmail(user.getEmail());
                    userDTO.setAdmin(user.getIsAdmin());
                    userDTO.setSalt(user.getSalt());
                    userDTO.setActive(user.getIsActive());
                    userDTO.setTimeCreated(user.getTimeCreated());
                    workloadDTO.setUser(userDTO);

                    workloadDTO.setTask(taskDTO);

                    WorkloadPKDTO workloadPKDTO = new WorkloadPKDTO();
                    WorkloadPK workloadPK = workload.getWorkloadPK();
                    workloadPKDTO.setTaskTaskId(workloadPK.getTaskTaskId());
                    workloadPKDTO.setTaskUserStoryStoryId(workloadPK.getTaskUserStoryStoryId());
                    workloadPKDTO.setUserUserId(workloadPK.getUserUserId());
                    workloadPKDTO.setWorkloadId(workloadPK.getWorkloadId());
                    workloadDTO.setWorkloadPK(workloadPKDTO);

                    List<WorkblockDTO> workblockDTOList = new ArrayList<WorkblockDTO>();
                    for (Workblock workblock : workload.getWorkblockList()) {
                      workblock =
                          ProxyManager.getWorkblockProxy()
                              .findWorkblock(workblock.getWorkblockPK());
                      WorkblockDTO workblockDTO = new WorkblockDTO();
                      workblockDTO.setTimeStart(workblock.getTimeStart());
                      workblockDTO.setTimeStop(workblock.getTimeStop());

                      workblockDTO.setWorkload(workloadDTO);

                      WorkblockPKDTO workblockPKDTO = new WorkblockPKDTO();
                      WorkblockPK workblockPK = workblock.getWorkblockPK();
                      workloadPKDTO.setWorkloadId(workblockPK.getWorkloadWorkloadId());
                      workblockPKDTO.setWorkloadTaskTaskId(workloadPK.getTaskTaskId());
                      workblockPKDTO.setWorkloadTaskUserStoryStoryId(
                          workblockPK.getWorkloadTaskUserStoryStoryId());
                      workblockPKDTO.setWorkloadUserUserId(workblockPK.getWorkloadUserUserId());
                      workblockPKDTO.setWorkloadWorkloadId(workblockPK.getWorkloadWorkloadId());
                      workblockDTO.setWorkblockPK(workblockPKDTO);

                      workblockDTOList.add(workblockDTO);
                    }
                    workloadDTO.setWorkblockList(workblockDTOList);

                    workloadDTOList.add(workloadDTO);
                  }
                  taskDTO.setWorkloadList(workloadDTOList);

                  taskDTOList.add(taskDTO);
                }
                userStoryDTO.setTaskList(taskDTOList);
              }
              userStoryDTOList.add(userStoryDTO);
            }
            sprintDTO.setUserStoryList(userStoryDTOList);
          }
          sprintDTOList.add(sprintDTO);
        }
        projectDTO.setSprintList(sprintDTOList);

      } else projectDTO.setSprintList(null);

      List<UserStoryDTO> userStoryDTOList = new ArrayList<UserStoryDTO>();
      if (p.getUserStoryList() != null) {
        for (UserStory us : p.getUserStoryList()) {
          UserStoryDTO userStoryDTO = new UserStoryDTO();
          userStoryDTO.setStoryId(us.getStoryId());
          userStoryDTO.setName(us.getName());
          userStoryDTO.setContent(us.getContent());
          userStoryDTO.setBusinessValue(us.getBusinessValue());
          userStoryDTO.setStatus(us.getStatus());
          if (us.getEstimateTime() != null) {
            userStoryDTO.setEstimateTime(us.getEstimateTime().doubleValue());
          } else userStoryDTO.setEstimateTime(null);
          userStoryDTO.setStoryId(us.getStoryId());
          userStoryDTO.setProjectProjectId(projectDTO);

          PriorityDTO priorityDTO = new PriorityDTO();
          priorityDTO.setPriorityId(us.getPriorityPriorityId().getPriorityId());
          priorityDTO.setName(us.getPriorityPriorityId().getName());
          userStoryDTO.setPriorityPriorityId(priorityDTO);

          List<AcceptanceTestDTO> acceptanceTestDTOList = new ArrayList<AcceptanceTestDTO>();
          for (AcceptanceTest at : us.getAcceptanceTestList()) {
            AcceptanceTestDTO acceptanceTestDTO = new AcceptanceTestDTO();
            acceptanceTestDTO.setAcceptanceTestId(at.getAcceptanceTestId());
            acceptanceTestDTO.setContent(at.getContent());
            acceptanceTestDTOList.add(acceptanceTestDTO);
          }
          userStoryDTO.setAcceptanceTestList(acceptanceTestDTOList);

          // TODO: Set taskList to userStoryDTO
          if (us.getTaskList() != null) {
            List<TaskDTO> taskDTOList = new ArrayList<TaskDTO>();
            for (Task task : us.getTaskList()) {
              task = ProxyManager.getTaskProxy().findTask(task.getTaskPK());
              TaskDTO taskDTO = new TaskDTO();
              taskDTO.setDescription(task.getDescription());
              taskDTO.setTimeRemaining(task.getTimeRemaining());
              taskDTO.setEstimatedTime(task.getEstimatedTime());
              taskDTO.setStatus(task.getStatus());
              taskDTO.setPreassignedUserName(task.getPreassignedUserName());
              taskDTO.setAssignedDate(task.getAssignedDate());

              taskDTO.setUserStory(userStoryDTO);

              TaskPKDTO taskPKDTO = new TaskPKDTO();
              taskPKDTO.setTaskId(task.getTaskPK().getTaskId());
              taskPKDTO.setUserStoryStoryId(task.getTaskPK().getUserStoryStoryId());
              taskDTO.setTaskPK(taskPKDTO);

              if (task.getUserUserId() != null) {
                User user = ProxyManager.getUserProxy().findUser(task.getUserUserId().getUserId());
                UserDTO userDTO = new UserDTO();
                userDTO.setUserId(user.getUserId());
                userDTO.setUsername(user.getUsername());
                userDTO.setPassword(user.getPassword());
                userDTO.setFirstName(user.getFirstName());
                userDTO.setLastName(user.getLastName());
                userDTO.setEmail(user.getEmail());
                userDTO.setAdmin(user.getIsAdmin());
                userDTO.setSalt(user.getSalt());
                userDTO.setActive(user.getIsActive());
                userDTO.setTimeCreated(user.getTimeCreated());
                taskDTO.setUserUserId(userDTO);
              }

              List<WorkloadDTO> workloadDTOList = new ArrayList<WorkloadDTO>();
              for (Workload workload : task.getWorkloadList()) {
                workload = ProxyManager.getWorkloadProxy().findWorkload(workload.getWorkloadPK());
                WorkloadDTO workloadDTO = new WorkloadDTO();
                workloadDTO.setDay(workload.getDay());
                workloadDTO.setTimeRemaining(workload.getTimeRemaining());
                workloadDTO.setTimeSpent(workload.getTimeSpent());

                User user = ProxyManager.getUserProxy().findUser(workload.getUser().getUserId());
                UserDTO userDTO = new UserDTO();
                userDTO.setUserId(user.getUserId());
                userDTO.setUsername(user.getUsername());
                userDTO.setPassword(user.getPassword());
                userDTO.setFirstName(user.getFirstName());
                userDTO.setLastName(user.getLastName());
                userDTO.setEmail(user.getEmail());
                userDTO.setAdmin(user.getIsAdmin());
                userDTO.setSalt(user.getSalt());
                userDTO.setActive(user.getIsActive());
                userDTO.setTimeCreated(user.getTimeCreated());
                workloadDTO.setUser(userDTO);

                workloadDTO.setTask(taskDTO);

                WorkloadPKDTO workloadPKDTO = new WorkloadPKDTO();
                WorkloadPK workloadPK = workload.getWorkloadPK();
                workloadPKDTO.setTaskTaskId(workloadPK.getTaskTaskId());
                workloadPKDTO.setTaskUserStoryStoryId(workloadPK.getTaskUserStoryStoryId());
                workloadPKDTO.setUserUserId(workloadPK.getUserUserId());
                workloadPKDTO.setWorkloadId(workloadPK.getWorkloadId());
                workloadDTO.setWorkloadPK(workloadPKDTO);

                List<WorkblockDTO> workblockDTOList = new ArrayList<WorkblockDTO>();
                for (Workblock workblock : workload.getWorkblockList()) {
                  workblock =
                      ProxyManager.getWorkblockProxy().findWorkblock(workblock.getWorkblockPK());
                  WorkblockDTO workblockDTO = new WorkblockDTO();
                  workblockDTO.setTimeStart(workblock.getTimeStart());
                  workblockDTO.setTimeStop(workblock.getTimeStop());

                  workblockDTO.setWorkload(workloadDTO);

                  WorkblockPKDTO workblockPKDTO = new WorkblockPKDTO();
                  WorkblockPK workblockPK = workblock.getWorkblockPK();
                  workloadPKDTO.setWorkloadId(workblockPK.getWorkloadWorkloadId());
                  workblockPKDTO.setWorkloadTaskTaskId(workloadPK.getTaskTaskId());
                  workblockPKDTO.setWorkloadTaskUserStoryStoryId(
                      workblockPK.getWorkloadTaskUserStoryStoryId());
                  workblockPKDTO.setWorkloadUserUserId(workblockPK.getWorkloadUserUserId());
                  workblockPKDTO.setWorkloadWorkloadId(workblockPK.getWorkloadWorkloadId());
                  workblockDTO.setWorkblockPK(workblockPKDTO);

                  workblockDTOList.add(workblockDTO);
                }
                workloadDTO.setWorkblockList(workblockDTOList);

                workloadDTOList.add(workloadDTO);
              }
              taskDTO.setWorkloadList(workloadDTOList);

              taskDTOList.add(taskDTO);
            }
            userStoryDTO.setTaskList(taskDTOList);
          } else userStoryDTO.setTaskList(null);

          SprintDTO sprintDTO = new SprintDTO();
          if (us.getSprint() != null) {
            SprintPKDTO sprintPKDTO = new SprintPKDTO();
            sprintPKDTO.setSprintId(us.getSprint().getSprintPK().getSprintId());
            sprintPKDTO.setProjectProjectId(us.getSprint().getSprintPK().getProjectProjectId());
            sprintDTO.setSprintPK(sprintPKDTO);
            sprintDTO.setSeqNumber(us.getSprint().getSeqNumber());
            sprintDTO.setStatus(us.getSprint().getStatus());
            sprintDTO.setStartDate(us.getSprint().getStartDate());
            sprintDTO.setEndDate(us.getSprint().getEndDate());
            sprintDTO.setVelocity(us.getSprint().getVelocity());
          } else sprintDTO = null;
          userStoryDTO.setSprint(sprintDTO);
          userStoryDTOList.add(userStoryDTO);
        }
        projectDTO.setUserStoryList(userStoryDTOList);
      }
      return projectDTO;
    } else return null;
  }