Java Code Examples for org.apache.hadoop.ipc.Server#getRemoteIp()

The following examples show how to use org.apache.hadoop.ipc.Server#getRemoteIp() . 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 File: TestRMAuditLogger.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Test the AuditLog format for failure events.
 */
private void testFailureLogFormatHelper(boolean checkIP, ApplicationId appId,
    ApplicationAttemptId attemptId, ContainerId containerId) {
  String fLog =
    RMAuditLogger.createFailureLog(USER, OPERATION, PERM, TARGET, DESC,
    appId, attemptId, containerId);
  StringBuilder expLog = new StringBuilder();
  expLog.append("USER=test\t");
  if (checkIP) {
    InetAddress ip = Server.getRemoteIp();
    expLog.append(Keys.IP.name() + "=" + ip.getHostAddress() + "\t");
  }
  expLog.append("OPERATION=oper\tTARGET=tgt\tRESULT=FAILURE\t");
  expLog.append("DESCRIPTION=description of an audit log");
  expLog.append("\tPERMISSIONS=admin group");
  if (appId != null) {
    expLog.append("\tAPPID=app_1");
  }
  if (attemptId != null) {
    expLog.append("\tAPPATTEMPTID=app_attempt_1");
  }
  if (containerId != null) {
    expLog.append("\tCONTAINERID=container_1");
  }
  assertEquals(expLog.toString(), fLog);
}
 
Example 2
Source File: TestRMAuditLogger.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Test the AuditLog format for successful events.
 */
private void testSuccessLogFormatHelper(boolean checkIP, ApplicationId appId,
    ApplicationAttemptId attemptId, ContainerId containerId) {
  String sLog = RMAuditLogger.createSuccessLog(USER, OPERATION, TARGET,
      appId, attemptId, containerId);
  StringBuilder expLog = new StringBuilder();
  expLog.append("USER=test\t");
  if (checkIP) {
    InetAddress ip = Server.getRemoteIp();
    expLog.append(Keys.IP.name() + "=" + ip.getHostAddress() + "\t");
  }
  expLog.append("OPERATION=oper\tTARGET=tgt\tRESULT=SUCCESS");

  if (appId != null) {
    expLog.append("\tAPPID=app_1");
  }
  if (attemptId != null) {
    expLog.append("\tAPPATTEMPTID=app_attempt_1");
  }
  if (containerId != null) {
    expLog.append("\tCONTAINERID=container_1");
  }
  assertEquals(expLog.toString(), sLog);
}
 
Example 3
Source File: TestNMAuditLogger.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Test the AuditLog format for failure events.
 */
private void testFailureLogFormatHelper(boolean checkIP, ApplicationId appId,
    ContainerId containerId) {
  String fLog =
    NMAuditLogger.createFailureLog(USER, OPERATION, TARGET, DESC, appId,
    containerId);
  StringBuilder expLog = new StringBuilder();
  expLog.append("USER=test\t");
  if (checkIP) {
    InetAddress ip = Server.getRemoteIp();
    expLog.append(Keys.IP.name() + "=" + ip.getHostAddress() + "\t");
  }
  expLog.append("OPERATION=oper\tTARGET=tgt\tRESULT=FAILURE\t");
  expLog.append("DESCRIPTION=description of an audit log");

  if (appId != null) {
    expLog.append("\tAPPID=app_1");
  }
  if (containerId != null) {
    expLog.append("\tCONTAINERID=container_1");
  }
  assertEquals(expLog.toString(), fLog);
}
 
Example 4
Source File: TestRMAuditLogger.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Test the AuditLog format for successful events.
 */
private void testSuccessLogFormatHelper(boolean checkIP, ApplicationId appId,
    ApplicationAttemptId attemptId, ContainerId containerId) {
  String sLog = RMAuditLogger.createSuccessLog(USER, OPERATION, TARGET,
      appId, attemptId, containerId);
  StringBuilder expLog = new StringBuilder();
  expLog.append("USER=test\t");
  if (checkIP) {
    InetAddress ip = Server.getRemoteIp();
    expLog.append(Keys.IP.name() + "=" + ip.getHostAddress() + "\t");
  }
  expLog.append("OPERATION=oper\tTARGET=tgt\tRESULT=SUCCESS");

  if (appId != null) {
    expLog.append("\tAPPID=app_1");
  }
  if (attemptId != null) {
    expLog.append("\tAPPATTEMPTID=app_attempt_1");
  }
  if (containerId != null) {
    expLog.append("\tCONTAINERID=container_1");
  }
  assertEquals(expLog.toString(), sLog);
}
 
Example 5
Source File: TestNMAuditLogger.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Test the AuditLog format for successful events.
 */
private void testSuccessLogFormatHelper(boolean checkIP, 
    ApplicationId appId, ContainerId containerId) {
  // check without the IP
  String sLog = NMAuditLogger.createSuccessLog(USER, OPERATION, TARGET,
      appId, containerId);
  StringBuilder expLog = new StringBuilder();
  expLog.append("USER=test\t");
  if (checkIP) {
    InetAddress ip = Server.getRemoteIp();
    expLog.append(Keys.IP.name() + "=" + ip.getHostAddress() + "\t");
  }
  expLog.append("OPERATION=oper\tTARGET=tgt\tRESULT=SUCCESS");
  if (appId != null) {
    expLog.append("\tAPPID=app_1");
  }
  if (containerId != null) {
    expLog.append("\tCONTAINERID=container_1");
  }
  assertEquals(expLog.toString(), sLog);
}
 
Example 6
Source File: TestRMAuditLogger.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Test the AuditLog format for successful events passing nulls.
 */
private void testSuccessLogNulls(boolean checkIP) {
  String sLog = RMAuditLogger.createSuccessLog(null, null, null, null, 
      null, null);
  StringBuilder expLog = new StringBuilder();
  expLog.append("USER=null\t");
  if (checkIP) {
    InetAddress ip = Server.getRemoteIp();
    expLog.append(Keys.IP.name() + "=" + ip.getHostAddress() + "\t");
  }
  expLog.append("OPERATION=null\tTARGET=null\tRESULT=SUCCESS");
  assertEquals(expLog.toString(), sLog);
}
 
Example 7
Source File: RMAuditLogger.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * A helper api to add remote IP address
 */
static void addRemoteIP(StringBuilder b) {
  InetAddress ip = Server.getRemoteIp();
  // ip address can be null for testcases
  if (ip != null) {
    add(Keys.IP, ip.getHostAddress(), b);
  }
}
 
Example 8
Source File: TestNMAuditLogger.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Test the AuditLog format for successful events passing nulls.
 */
private void testSuccessLogNulls(boolean checkIP) {
  String sLog = NMAuditLogger.createSuccessLog(null, null, null,
      null, null);
  StringBuilder expLog = new StringBuilder();
  expLog.append("USER=null\t");
  if (checkIP) {
    InetAddress ip = Server.getRemoteIp();
    expLog.append(Keys.IP.name() + "=" + ip.getHostAddress() + "\t");
  }
  expLog.append("OPERATION=null\tTARGET=null\tRESULT=SUCCESS");
  assertEquals(expLog.toString(), sLog);
}
 
Example 9
Source File: NMAuditLogger.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * A helper api to add remote IP address
 */
static void addRemoteIP(StringBuilder b) {
  InetAddress ip = Server.getRemoteIp();
  // ip address can be null for testcases
  if (ip != null) {
    add(Keys.IP, ip.getHostAddress(), b);
  }
}
 
Example 10
Source File: HSAuditLogger.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * A helper api to add remote IP address
 */
static void addRemoteIP(StringBuilder b) {
  InetAddress ip = Server.getRemoteIp();
  // ip address can be null for testcases
  if (ip != null) {
    add(Keys.IP, ip.getHostAddress(), b);
  }
}
 
Example 11
Source File: AuditLogger.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * A helper api to add remote IP address
 */
static void addRemoteIP(StringBuilder b) {
  InetAddress ip = Server.getRemoteIp();
  // ip address can be null for testcases
  if (ip != null) {
    add(Keys.IP, ip.getHostAddress(), b);
  }
}
 
Example 12
Source File: HSAuditLogger.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * A helper api to add remote IP address
 */
static void addRemoteIP(StringBuilder b) {
  InetAddress ip = Server.getRemoteIp();
  // ip address can be null for testcases
  if (ip != null) {
    add(Keys.IP, ip.getHostAddress(), b);
  }
}
 
Example 13
Source File: TestAuditLogger.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Test the AuditLog format for successful events.
 */
private void testSuccessLogFormat(boolean checkIP) {
  // check without the IP
  String sLog = AuditLogger.createSuccessLog(USER, OPERATION, TARGET);
  StringBuilder expLog = new StringBuilder();
  expLog.append("USER=test\t");
  if (checkIP) {
    InetAddress ip = Server.getRemoteIp();
    expLog.append(Keys.IP.name() + "=" + ip.getHostAddress() + "\t");
  }
  expLog.append("OPERATION=oper\tTARGET=tgt\tRESULT=SUCCESS");
  assertEquals(expLog.toString(), sLog);

}
 
Example 14
Source File: RangerYarnAuthorizer.java    From ranger with Apache License 2.0 5 votes vote down vote up
private static String getRemoteIp() {
	String ret = null;
	InetAddress ip = Server.getRemoteIp();
	if (ip != null) {
		ret = ip.getHostAddress();
	}
	return ret;
}
 
Example 15
Source File: TestRMAuditLogger.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Test the AuditLog format for successful events passing nulls.
 */
private void testSuccessLogNulls(boolean checkIP) {
  String sLog = RMAuditLogger.createSuccessLog(null, null, null, null, 
      null, null);
  StringBuilder expLog = new StringBuilder();
  expLog.append("USER=null\t");
  if (checkIP) {
    InetAddress ip = Server.getRemoteIp();
    expLog.append(Keys.IP.name() + "=" + ip.getHostAddress() + "\t");
  }
  expLog.append("OPERATION=null\tTARGET=null\tRESULT=SUCCESS");
  assertEquals(expLog.toString(), sLog);
}
 
Example 16
Source File: RMAuditLogger.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * A helper api to add remote IP address
 */
static void addRemoteIP(StringBuilder b) {
  InetAddress ip = Server.getRemoteIp();
  // ip address can be null for testcases
  if (ip != null) {
    add(Keys.IP, ip.getHostAddress(), b);
  }
}
 
Example 17
Source File: TestAuditLogger.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Test the AuditLog format for failure events.
 */
private void testFailureLogFormat(boolean checkIP, String perm) {
  String fLog =
    AuditLogger.createFailureLog(USER, OPERATION, perm, TARGET, DESC);
  StringBuilder expLog = new StringBuilder();
  expLog.append("USER=test\t");
  if (checkIP) {
    InetAddress ip = Server.getRemoteIp();
    expLog.append(Keys.IP.name() + "=" + ip.getHostAddress() + "\t");
  }
  expLog.append("OPERATION=oper\tTARGET=tgt\tRESULT=FAILURE\t");
  expLog.append("DESCRIPTION=description of an audit log\t");
  expLog.append("PERMISSIONS=" + perm);
  assertEquals(expLog.toString(), fLog);
}
 
Example 18
Source File: TestNMAuditLogger.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Test the AuditLog format for successful events passing nulls.
 */
private void testSuccessLogNulls(boolean checkIP) {
  String sLog = NMAuditLogger.createSuccessLog(null, null, null,
      null, null);
  StringBuilder expLog = new StringBuilder();
  expLog.append("USER=null\t");
  if (checkIP) {
    InetAddress ip = Server.getRemoteIp();
    expLog.append(Keys.IP.name() + "=" + ip.getHostAddress() + "\t");
  }
  expLog.append("OPERATION=null\tTARGET=null\tRESULT=SUCCESS");
  assertEquals(expLog.toString(), sLog);
}
 
Example 19
Source File: AuditLogger.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * A helper api to add remote IP address
 */
static void addRemoteIP(StringBuilder b) {
  InetAddress ip = Server.getRemoteIp();
  // ip address can be null for testcases
  if (ip != null) {
    add(Keys.IP, ip.getHostAddress(), b);
  }
}
 
Example 20
Source File: SCMNodeManager.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
/**
 * Register the node if the node finds that it is not registered with any
 * SCM.
 *
 * @param datanodeDetails - Send datanodeDetails with Node info.
 *                        This function generates and assigns new datanode ID
 *                        for the datanode. This allows SCM to be run
 *                        independent
 *                        of Namenode if required.
 * @param nodeReport      NodeReport.
 * @return SCMRegisteredResponseProto
 */
@Override
public RegisteredCommand register(
    DatanodeDetails datanodeDetails, NodeReportProto nodeReport,
    PipelineReportsProto pipelineReportsProto) {

  InetAddress dnAddress = Server.getRemoteIp();
  if (dnAddress != null) {
    // Mostly called inside an RPC, update ip and peer hostname
    datanodeDetails.setHostName(dnAddress.getHostName());
    datanodeDetails.setIpAddress(dnAddress.getHostAddress());
  }
  try {
    String dnsName;
    String networkLocation;
    datanodeDetails.setNetworkName(datanodeDetails.getUuidString());
    if (useHostname) {
      dnsName = datanodeDetails.getHostName();
    } else {
      dnsName = datanodeDetails.getIpAddress();
    }
    networkLocation = nodeResolve(dnsName);
    if (networkLocation != null) {
      datanodeDetails.setNetworkLocation(networkLocation);
    }
    nodeStateManager.addNode(datanodeDetails);
    clusterMap.add(datanodeDetails);
    addEntryTodnsToUuidMap(dnsName, datanodeDetails.getUuidString());
    // Updating Node Report, as registration is successful
    processNodeReport(datanodeDetails, nodeReport);
    LOG.info("Registered Data node : {}", datanodeDetails);
  } catch (NodeAlreadyExistsException e) {
    if (LOG.isTraceEnabled()) {
      LOG.trace("Datanode is already registered. Datanode: {}",
          datanodeDetails.toString());
    }
  }

  return RegisteredCommand.newBuilder().setErrorCode(ErrorCode.success)
      .setDatanode(datanodeDetails)
      .setClusterID(this.scmStorageConfig.getClusterID())
      .build();
}