Java Code Examples for org.apache.hadoop.metrics.MetricsException

The following examples show how to use org.apache.hadoop.metrics.MetricsException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   Source File: AbstractMetricsContext.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Adds two numbers, coercing the second to the type of the first.
 *
 */
private Number sum(Number a, Number b) {
  if (a instanceof Integer) {
    return Integer.valueOf(a.intValue() + b.intValue());
  }
  else if (a instanceof Float) {
    return new Float(a.floatValue() + b.floatValue());
  }
  else if (a instanceof Short) {
    return Short.valueOf((short)(a.shortValue() + b.shortValue()));
  }
  else if (a instanceof Byte) {
    return Byte.valueOf((byte)(a.byteValue() + b.byteValue()));
  }
  else if (a instanceof Long) {
    return Long.valueOf((a.longValue() + b.longValue()));
  }
  else {
    // should never happen
    throw new MetricsException("Invalid number type");
  }
          
}
 
Example 2
Source Project: big-c   Source File: AbstractMetricsContext.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Adds two numbers, coercing the second to the type of the first.
 *
 */
private Number sum(Number a, Number b) {
  if (a instanceof Integer) {
    return Integer.valueOf(a.intValue() + b.intValue());
  }
  else if (a instanceof Float) {
    return new Float(a.floatValue() + b.floatValue());
  }
  else if (a instanceof Short) {
    return Short.valueOf((short)(a.shortValue() + b.shortValue()));
  }
  else if (a instanceof Byte) {
    return Byte.valueOf((byte)(a.byteValue() + b.byteValue()));
  }
  else if (a instanceof Long) {
    return Long.valueOf((a.longValue() + b.longValue()));
  }
  else {
    // should never happen
    throw new MetricsException("Invalid number type");
  }
          
}
 
Example 3
Source Project: RDFS   Source File: JMXContext.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void init(String contextName, ContextFactory factory) {
  super.init(contextName, factory);
  initAllowedRecords();
  
  String periodStr = getAttribute(PERIOD_PROPERTY);
  if (periodStr != null) {
    int period = 0;
    try {
      period = Integer.parseInt(periodStr);
    } catch (NumberFormatException nfe) {
    }
    if (period <= 0) {
      throw new MetricsException("Invalid period: " + periodStr);
    }
    setPeriod(period);
  }
}
 
Example 4
Source Project: RDFS   Source File: AbstractMetricsContext.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Adds two numbers, coercing the second to the type of the first.
 *
 */
private Number sum(Number a, Number b) {
  if (a instanceof Integer) {
    return Integer.valueOf(a.intValue() + b.intValue());
  }
  else if (a instanceof Float) {
    return new Float(a.floatValue() + b.floatValue());
  }
  else if (a instanceof Short) {
    return Short.valueOf((short)(a.shortValue() + b.shortValue()));
  }
  else if (a instanceof Byte) {
    return Byte.valueOf((byte)(a.byteValue() + b.byteValue()));
  }
  else if (a instanceof Long) {
    return Long.valueOf((a.longValue() + b.longValue()));
  }
  else {
    // should never happen
    throw new MetricsException("Invalid number type");
  }
          
}
 
Example 5
Source Project: hadoop-gpu   Source File: AbstractMetricsContext.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Adds two numbers, coercing the second to the type of the first.
 *
 */
private Number sum(Number a, Number b) {
  if (a instanceof Integer) {
    return Integer.valueOf(a.intValue() + b.intValue());
  }
  else if (a instanceof Float) {
    return new Float(a.floatValue() + b.floatValue());
  }
  else if (a instanceof Short) {
    return Short.valueOf((short)(a.shortValue() + b.shortValue()));
  }
  else if (a instanceof Byte) {
    return Byte.valueOf((byte)(a.byteValue() + b.byteValue()));
  }
  else if (a instanceof Long) {
    return Long.valueOf((a.longValue() + b.longValue()));
  }
  else {
    // should never happen
    throw new MetricsException("Invalid number type");
  }
          
}
 
Example 6
Source Project: hadoop-gpu   Source File: NullContextWithUpdateThread.java    License: Apache License 2.0 6 votes vote down vote up
public void init(String contextName, ContextFactory factory) {
  super.init(contextName, factory);
  
  // If period is specified, use it, otherwise the default is good enough
      
  String periodStr = getAttribute(PERIOD_PROPERTY);
  if (periodStr != null) {
    int period = 0;
    try {
      period = Integer.parseInt(periodStr);
    } catch (NumberFormatException nfe) {
    }
    if (period <= 0) {
      throw new MetricsException("Invalid period: " + periodStr);
    }
    setPeriod(period);
  }
}
 
Example 7
Source Project: hadoop-gpu   Source File: FileContext.java    License: Apache License 2.0 6 votes vote down vote up
public void init(String contextName, ContextFactory factory) {
  super.init(contextName, factory);
      
  String fileName = getAttribute(FILE_NAME_PROPERTY);
  if (fileName != null) {
    file = new File(fileName);
  }
      
  String periodStr = getAttribute(PERIOD_PROPERTY);
  if (periodStr != null) {
    int period = 0;
    try {
      period = Integer.parseInt(periodStr);
    } catch (NumberFormatException nfe) {
    }
    if (period <= 0) {
      throw new MetricsException("Invalid period: " + periodStr);
    }
    setPeriod(period);
  }
}
 
Example 8
Source Project: hadoop   Source File: AbstractMetricsContext.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * If a period is set in the attribute passed in, override
 * the default with it.
 */
protected void parseAndSetPeriod(String attributeName) {
  String periodStr = getAttribute(attributeName);
  if (periodStr != null) {
    int period = 0;
    try {
      period = Integer.parseInt(periodStr);
    } catch (NumberFormatException nfe) {
    }
    if (period <= 0) {
      throw new MetricsException("Invalid period: " + periodStr);
    }
    setPeriod(period);
  }
}
 
Example 9
Source Project: big-c   Source File: AbstractMetricsContext.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * If a period is set in the attribute passed in, override
 * the default with it.
 */
protected void parseAndSetPeriod(String attributeName) {
  String periodStr = getAttribute(attributeName);
  if (periodStr != null) {
    int period = 0;
    try {
      period = Integer.parseInt(periodStr);
    } catch (NumberFormatException nfe) {
    }
    if (period <= 0) {
      throw new MetricsException("Invalid period: " + periodStr);
    }
    setPeriod(period);
  }
}
 
Example 10
Source Project: RDFS   Source File: AbstractMetricsContext.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * If a period is set in the attribute passed in, override
 * the default with it.
 */
protected void parseAndSetPeriod(String attributeName) {
  String periodStr = getAttribute(attributeName);
  if (periodStr != null) {
    int period = 0;
    try {
      period = Integer.parseInt(periodStr);
    } catch (NumberFormatException nfe) {
    }
    if (period <= 0) {
      throw new MetricsException("Invalid period: " + periodStr);
    }
    setPeriod(period);
  }
}
 
Example 11
Source Project: hadoop-gpu   Source File: GangliaContext.java    License: Apache License 2.0 5 votes vote down vote up
public void init(String contextName, ContextFactory factory) {
  super.init(contextName, factory);
      
  String periodStr = getAttribute(PERIOD_PROPERTY);
  if (periodStr != null) {
    int period = 0;
    try {
      period = Integer.parseInt(periodStr);
    } catch (NumberFormatException nfe) {
    }
    if (period <= 0) {
      throw new MetricsException("Invalid period: " + periodStr);
    }
    setPeriod(period);
  }
      
  metricsServers = 
    Util.parse(getAttribute(SERVERS_PROPERTY), DEFAULT_PORT); 
      
  unitsTable = getAttributeTable(UNITS_PROPERTY);
  slopeTable = getAttributeTable(SLOPE_PROPERTY);
  tmaxTable  = getAttributeTable(TMAX_PROPERTY);
  dmaxTable  = getAttributeTable(DMAX_PROPERTY);
      
  try {
    datagramSocket = new DatagramSocket();
  }
  catch (SocketException se) {
    se.printStackTrace();
  }
}
 
Example 12
Source Project: RDFS   Source File: TaskTracker.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Build and transmit the heart beat to the JobTracker
 * @param jobClient The jobTracker RPC handle
 * @param heartbeatResponseId Last heartbeat response received
 * @param status TaskTrackerStatus to transmit
 * @return false if the tracker was unknown
 * @throws IOException
 */
protected HeartbeatResponse transmitHeartBeat(
    InterTrackerProtocol jobClient, short heartbeatResponseId,
    TaskTrackerStatus status) throws IOException {
  //
  // Check if we should ask for a new Task
  //
  boolean askForNewTask;
  long localMinSpaceStart;
  synchronized (this) {
    askForNewTask =
      ((status.countOccupiedMapSlots() < maxMapSlots ||
        status.countOccupiedReduceSlots() < maxReduceSlots) &&
       acceptNewTasks);
    localMinSpaceStart = minSpaceStart;
  }
  if (askForNewTask) {
    checkLocalDirs(fConf.getLocalDirs());
    askForNewTask = enoughFreeSpace(localMinSpaceStart);
    gatherResourceStatus(status);
  }
  //add node health information

  TaskTrackerHealthStatus healthStatus = status.getHealthStatus();
  synchronized (this) {
    if (healthChecker != null) {
      healthChecker.setHealthStatus(healthStatus);
    } else {
      healthStatus.setNodeHealthy(true);
      healthStatus.setLastReported(0L);
      healthStatus.setHealthReport("");
    }
  }
  //
  // Xmit the heartbeat
  //
  HeartbeatResponse heartbeatResponse = jobClient.heartbeat(status,
                                                            justStarted,
                                                            justInited,
                                                            askForNewTask,
                                                            heartbeatResponseId);

  synchronized (this) {
    for (TaskStatus taskStatus : status.getTaskReports()) {
      if (taskStatus.getRunState() != TaskStatus.State.RUNNING &&
          taskStatus.getRunState() != TaskStatus.State.UNASSIGNED &&
          taskStatus.getRunState() != TaskStatus.State.COMMIT_PENDING &&
          !taskStatus.inTaskCleanupPhase()) {
        if (taskStatus.getIsMap()) {
          mapTotal--;
        } else {
          reduceTotal--;
        }
        try {
          myInstrumentation.completeTask(taskStatus.getTaskID());
        } catch (MetricsException me) {
          LOG.warn("Caught: " + StringUtils.stringifyException(me));
        }
        removeRunningTask(taskStatus.getTaskID());
      }
    }

    // Clear transient status information which should only
    // be sent once to the JobTracker
    for (TaskInProgress tip: runningTasks.values()) {
      tip.getStatus().clearStatus();
    }
  }

  return heartbeatResponse;
}