Пример #1
0
  private boolean schedule() {
    try {
      /* hash com os workers em processamento. Indexado pela tarefa*/
      workingOn = new Hashtable();
      currentStatus = Phase.MAP;
      while (!currentStatus.equals(Phase.ERROR)) {

        Worker worker = (Worker) workerQueue.take();
        Task task = (Task) taskQueue.take();
        TaskStatus op = task.getStatus();

        /* termina escalonamento se encontra flag de fim*/
        if (op.value() == TaskStatus._END) {
          break;
        }
        workingOn.put(task, worker);
        worker.execute(channel, task);
      }

      if (currentStatus.equals(Phase.ERROR)) {
        return false;
      }

      return true;
    } catch (Exception e) {
      exception = LogError.getStackTrace(e);
      reporter.report(0, "MasterServant::schedule - Escalonamento interrompido. \n" + exception);
      return false;
    }
  }
Пример #2
0
  public void start(String configFileName, Reporter reporter)
      throws PropertiesException, ConectionToExecNodesException, ChannelException,
          WorkerInstantiationException, TaskInstantiationException, StartFailureException {
    this.reporter = reporter;
    reporter.report(1, "MasterServant::start - Lendo configuracoes de " + configFileName);

    /* lê arquivo de configuração */
    if (!getProperties(configFileName)) {
      throw new PropertiesException();
    }
    reporter.report(1, "MasterServant::start - Arquivo de configuracao lido");

    /* cria objeto que inicializa workers e fila de tarefas */
    try {
      initializer = new WorkerInitializer(this);
    } catch (Exception e) {
      throw new WorkerInstantiationException();
    }
    reporter.report(1, "MasterServant::start - WorkerInitializer instanciado");

    /* conecta-se com os execution nodes dos workers*/
    reporter.report(1, "MasterServant::start - Conectando aos outros execution nodes");
    hashNodes = this.initializer.connectToExecNodes();
    if (hashNodes == null) {
      throw new ConectionToExecNodesException();
    }
    reporter.report(1, "MasterServant::start - Conectado ao execution node dos workers");

    /* cria canal de evento entre master e workers*/
    reporter.report(1, "MasterServant::start - Criando canal de evento entre master e workers");
    channel = initializer.buildChannel();
    if (channel == null) {
      throw new ChannelException();
    }

    /*instancia workers*/
    reporter.report(1, "MasterServant::start - Instanciando Workers");
    workerQueue = initializer.buildWorkerQueue();
    if (workerQueue == null) {
      throw new WorkerInstantiationException();
    }

    /*instancia tarefas*/
    reporter.report(1, "MasterServant::start - Instanciando Tarefas");
    ioformat = initializer.createIOFormatServant(ioformatClassName);
    if (ioformat == null) {
      throw new TaskInstantiationException();
    }

    taskQueue = initializer.buildTaskQueue();
    if ((taskQueue == null) || (taskQueue.toArray().length == 0)) {
      throw new TaskInstantiationException();
    }
    num_partitions = taskQueue.toArray().length;

    /* inicia escalonamento das tarefas map-reduce*/
    reporter.report(1, "MasterServant::start - Iniciando escalonamento");
    if (!schedule()) {
      initializer.finish();
      throw new StartFailureException();
    }
    initializer.finish();
  }
Пример #3
0
  private boolean getProperties(String configFileName) {
    this.configFileName = configFileName;
    this.config = new Properties();

    try {
      config.load(new FileInputStream(configFileName));
    } catch (IOException e) {
      exception = LogError.getStackTrace(e);
      reporter.report(
          0,
          "MasterServant::getProperties - Erro ao ler arquivo de configuracao "
              + configFileName
              + ".\n"
              + exception);
      return false;
    }

    /* Obtendo configuracoes para o mapreduce*/
    masterHost = this.config.getProperty("mapred.Master.corbaloc-host");
    if (masterHost == null) {
      reporter.report(0, "MasterServant::getProperties - Erro ao obter host onde Master executara");
      return false;
    }

    masterPort = this.config.getProperty("mapred.Master.corbaloc-port");
    if (masterPort == null) {
      reporter.report(0, "MasterServant::getProperties - Erro ao obter port onde Master executara");
      return false;
    }

    inputFileName = this.config.getProperty("mapred.Input.name");
    if (inputFileName == null) {
      reporter.report(0, "MasterServant::getProperties - Erro ao ler nome do arquivo de entrada");
      return false;
    }

    containerName = this.config.getProperty("mapred.Master.container-name");
    if (containerName == null) {
      reporter.report(0, "MasterServant::getProperties - Erro ao ler nome do container do master");
      return false;
    }

    mapperServantName = this.config.getProperty("mapred.Mapper.servant-name");
    if (mapperServantName == null) {
      reporter.report(0, "MasterServant::getProperties - Erro ao ler nome do servant Mapper");
      return false;
    }

    reducerServantName = this.config.getProperty("mapred.Reducer.servant-name");
    if (reducerServantName == null) {
      reporter.report(0, "MasterServant::getProperties - Erro ao ler nome do servant Reducer");
      return false;
    }

    partitionerServantName = this.config.getProperty("mapred.Partitioner.servant-name");
    if (mapperServantName == null) {
      reporter.report(0, "MasterServant::getProperties - Erro ao ler nome do servant Partitioner");
      return false;
    }

    String execNodes = this.config.getProperty("mapred.Workers.exec-nodes");
    if (execNodes == null) {
      reporter.report(
          0,
          "MasterServant::getProperties - Erro ao ler execution nodes "
              + "onde workers serao instanciados");
      return false;
    } else {
      execNodeList = execNodes.split(";");
    }

    num_mappers =
        Integer.parseInt(
            this.config.getProperty("mapred.Mappers.number", String.valueOf(execNodeList.length)));
    num_reducers = Integer.parseInt(this.config.getProperty("mapred.Reducers.number", "0"));
    if (num_mappers < execNodeList.length) {
      reporter.report(
          0,
          "MasterServant::getProperties - Numero de mappers nao pode ser menor que "
              + "numero de execution nodes");
      return false;
    }
    if (num_mappers < num_reducers) {
      reporter.report(
          0,
          "MasterServant::getProperties - Numero de mappers nao pode ser menor que "
              + "numero de reducers");
      return false;
    }

    combineFlag =
        Boolean.valueOf(this.config.getProperty("mapred.Combine.flag", "false")).booleanValue();
    if (combineFlag) {
      combinerServantName =
          this.config.getProperty("mapred.Combiner.servant-name", reducerServantName);
    }

    ioformatClassName = this.config.getProperty("mapred.IOFormat.class-name");
    if (ioformatClassName == null) {
      reporter.report(
          0,
          "MasterServant::getProperties - Erro ao ler nome da classe que implementa "
              + "a interface IOFormat");
      return false;
    }

    joinFlag = Boolean.valueOf(this.config.getProperty("mapred.Join.flag", "true")).booleanValue();
    joinFileName = inputFileName.split(".txt") + "Result" + ".txt";
    joinFileName = this.config.getProperty("mapred.Join.file-name", joinFileName);

    return true;
  }