예제 #1
0
 @Override
 public String getUsername(Context ctx) {
   Option<User> user = ContextUtil.getCurrentUser(ctx);
   if (user.isEmpty()) {
     return null;
   }
   return user.get().username;
 }
  private Option<SakaiBulkDownloadFolder> findBulkDownloadFolder()
      throws NotValidDownloadFolderException {
    File[] foundFiles =
        folder.listFiles(
            new FileFilter() {

              public boolean accept(File path) {
                return path.isDirectory()
                    && path.getName().equals(MergingEnvironment.get().getAssignmentName());
              }
            });
    if (foundFiles.length > 0) {
      return Option.apply(new SakaiBulkDownloadFolder(foundFiles[0].getAbsolutePath()));
    }

    Option<File> zipFile =
        DirectoryUtils.find(
            folder,
            new FileFilter() {
              public boolean accept(File pathname) {
                return pathname.getName().endsWith(".zip");
              }
            });
    if (zipFile.isEmpty()) {
      return Option.empty();
    }

    // Extract the zip to look for the folder
    try {
      System.out.println("Extracting bulk downloads...");
      ZipFile zip = new ZipFile(zipFile.get());
      zip.extractAll(folder.getAbsolutePath());

      // Look for a folder, taking the first one found.
      Option<File> resultsFolder =
          DirectoryUtils.find(
              folder,
              new FileFilter() {
                public boolean accept(File pathname) {
                  return pathname.isDirectory()
                      && pathname.getName().equals(MergingEnvironment.get().getAssignmentName());
                }
              });
      if (resultsFolder.isDefined()) {
        try {
          return Option.apply(new SakaiBulkDownloadFolder(resultsFolder.get().getAbsolutePath()));
        } catch (Exception e) {
          return Option.empty();
        }
      }
      System.out.println("done.");
      return Option.empty();
    } catch (ZipException e) {
      return Option.empty();
    }
  }
 public SakaiGraderResultFolder(String path)
     throws NotValidResultFolderException, NotValidDownloadFolderException {
   File topFolder = new File(path);
   folder = new File(topFolder, MergingEnvironment.get().getAssignmentName());
   if (!(folder.exists() && folder.isDirectory())) {
     throw new NotValidResultFolderException("Missing assignment folder: " + path);
   }
   spreadsheetFile = new File(folder, "grades.xlsx");
   Option<SakaiBulkDownloadFolder> bulkDownloadOption = findBulkDownloadFolder();
   if (bulkDownloadOption.isEmpty()) {
     throw new NotValidResultFolderException("Missing a bulk download folder");
   }
   bulkDownloadFolder = bulkDownloadOption.get();
 }
예제 #4
0
  @Override
  public List<String> getNewMessages() {
    if (!isConnected) {
      throw new IllegalStateException("The cluster has been connected to the ApplicationMaster.");
    }

    if (hasBeenStopped()) {
      throw new RuntimeException("The FlinkYarnCluster has already been stopped");
    }
    List<String> ret = new ArrayList<String>();

    // get messages from ApplicationClient (locally)
    while (true) {
      Object result = null;
      try {
        Future<Object> response =
            Patterns.ask(
                applicationClient, Messages.getLocalGetYarnMessage(), new Timeout(akkaDuration));

        result = Await.result(response, akkaDuration);
      } catch (Exception ioe) {
        LOG.warn("Error retrieving the YARN messages locally", ioe);
        break;
      }

      if (!(result instanceof Option)) {
        throw new RuntimeException(
            "LocalGetYarnMessage requires a response of type "
                + "Option. Instead the response is of type "
                + result.getClass()
                + ".");
      } else {
        Option messageOption = (Option) result;
        LOG.debug("Received message option {}", messageOption);
        if (messageOption.isEmpty()) {
          break;
        } else {
          Object obj = messageOption.get();

          if (obj instanceof Messages.YarnMessage) {
            Messages.YarnMessage msg = (Messages.YarnMessage) obj;
            ret.add("[" + msg.date() + "] " + msg.message());
          } else {
            LOG.warn("LocalGetYarnMessage returned unexpected type: " + messageOption);
          }
        }
      }
    }
    return ret;
  }
  @Override
  public TestCaseResult test(Project project, boolean autoGrade)
      throws NotAutomatableException, NotGradableException {
    // There should be a setter (editable) for the command
    if (project.getClassesManager().isEmpty()) throw new NotGradableException();
    Option<ClassDescription> classDescription =
        new RootTagFinder(project).findClass("Command Interpreter");
    if (classDescription.isEmpty()) {
      if (autoGrade) throw new NotAutomatableException();
      classDescription = ManualClassFinder.find(project, "Command Interpreter");
    }

    Class<?> _class = classDescription.get().getJavaClass();
    Method[] methods = _class.getMethods();
    for (Method method : methods) {
      if (method.getName().startsWith("set")) return pass(autoGrade);
    }
    return fail("Couldn't find an editable property", autoGrade);
  }
  @Override
  protected void initialize() throws Exception {
    LOG.info("Initializing Mesos resource master");

    workerStore.start();

    // create the scheduler driver to communicate with Mesos
    schedulerCallbackHandler = new SchedulerProxy(self());

    // register with Mesos
    FrameworkInfo.Builder frameworkInfo = mesosConfig.frameworkInfo().clone().setCheckpoint(true);

    Option<Protos.FrameworkID> frameworkID = workerStore.getFrameworkID();
    if (frameworkID.isEmpty()) {
      LOG.info("Registering as new framework.");
    } else {
      LOG.info(
          "Recovery scenario: re-registering using framework ID {}.", frameworkID.get().getValue());
      frameworkInfo.setId(frameworkID.get());
    }

    MesosConfiguration initializedMesosConfig = mesosConfig.withFrameworkInfo(frameworkInfo);
    MesosConfiguration.logMesosConfig(LOG, initializedMesosConfig);
    schedulerDriver = initializedMesosConfig.createDriver(schedulerCallbackHandler, false);

    // create supporting actors
    connectionMonitor = createConnectionMonitor();
    launchCoordinator = createLaunchCoordinator();
    reconciliationCoordinator = createReconciliationCoordinator();
    taskRouter = createTaskRouter();

    recoverWorkers();

    connectionMonitor.tell(new ConnectionMonitor.Start(), self());
    schedulerDriver.start();
  }