Example usage for java.net InetAddress getCanonicalHostName

List of usage examples for java.net InetAddress getCanonicalHostName

Introduction

In this page you can find the example usage for java.net InetAddress getCanonicalHostName.

Prototype

public String getCanonicalHostName() 

Source Link

Document

Gets the fully qualified domain name for this IP address.

Usage

From source file:dk.netarkivet.harvester.harvesting.WARCWriterProcessor.java

/**
 * Return relevant values as header-like fields (here ANVLRecord, but spec-defined "application/warc-fields" type
 * when written). Field names from from DCMI Terms and the WARC/0.17 specification.
 *
 * @see org.archive.crawler.framework.WriterPoolProcessor#getFirstrecordBody(java.io.File)
 *//*from w  w w .j a  v a  2s .com*/
@Override
protected String getFirstrecordBody(File orderFile) {
    ANVLRecord record = new ANVLRecord(7);
    record.addLabelValue("software", "Heritrix/" + Heritrix.getVersion() + " http://crawler.archive.org");

    try {
        InetAddress host = InetAddress.getLocalHost();
        record.addLabelValue("ip", host.getHostAddress());
        record.addLabelValue("hostname", host.getCanonicalHostName());
    } catch (UnknownHostException e) {
        logger.log(Level.WARNING, "unable top obtain local crawl engine host", e);
    }

    // conforms to ISO 28500:2009 as of May 2009
    // as described at http://bibnum.bnf.fr/WARC/
    // latest draft as of November 2008
    record.addLabelValue("format", "WARC File Format 1.0");
    record.addLabelValue("conformsTo", "http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf");

    // Get other values from order.xml
    try {
        Document doc = XmlUtils.getDocument(orderFile);
        addIfNotBlank(record, "operator", XmlUtils.xpathOrNull(doc, "//meta/operator"));
        addIfNotBlank(record, "publisher", XmlUtils.xpathOrNull(doc, "//meta/organization"));
        addIfNotBlank(record, "audience", XmlUtils.xpathOrNull(doc, "//meta/audience"));
        addIfNotBlank(record, "isPartOf", XmlUtils.xpathOrNull(doc, "//meta/name"));

        // disabling "created" field per HER-1634
        // though it's theoretically useful as a means of distinguishing
        // one crawl from another, the current usage/specification is too
        // vague... in particular a 'created' field in the 'warcinfo' is
        // reasonable to interpret as applying to the WARC-unit, rather
        // than the crawl-job-unit so we remove it and see if anyone
        // complains or makes a case for restoring it in a less-ambiguous
        // manner
        // String rawDate = XmlUtils.xpathOrNull(doc,"//meta/date");
        // if(StringUtils.isNotBlank(rawDate)) {
        // Date date;
        // try {
        // date = ArchiveUtils.parse14DigitDate(rawDate);
        // addIfNotBlank(record,"created",ArchiveUtils.getLog14Date(date));
        // } catch (ParseException e) {
        // logger.log(Level.WARNING,"obtaining warc created date",e);
        // }
        // }

        addIfNotBlank(record, "description", XmlUtils.xpathOrNull(doc, "//meta/description"));
        addIfNotBlank(record, "robots",
                XmlUtils.xpathOrNull(doc, "//newObject[@name='robots-honoring-policy']/string[@name='type']"));
        addIfNotBlank(record, "http-header-user-agent",
                XmlUtils.xpathOrNull(doc, "//map[@name='http-headers']/string[@name='user-agent']"));
        addIfNotBlank(record, "http-header-from",
                XmlUtils.xpathOrNull(doc, "//map[@name='http-headers']/string[@name='from']"));
        if (metadataMap == null) {
            //metadataMap = getMetadataItems();
            XPathFactory factory = XPathFactory.newInstance();
            XPath xpath = factory.newXPath();
            XPathExpression expr = xpath.compile(H1HeritrixTemplate.METADATA_ITEMS_XPATH);
            Node node = (Node) expr.evaluate(doc, XPathConstants.NODE);
            //NodeList nodeList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
            //Node node = nodeList.item(0);
            if (node != null) {
                NodeList nodeList = node.getChildNodes();
                if (nodeList != null) {
                    metadataMap = new HashMap();
                    for (int i = 0; i < nodeList.getLength(); ++i) {
                        node = nodeList.item(i);
                        if (node.getNodeType() == Node.ELEMENT_NODE) {
                            String typeName = node.getNodeName();
                            if ("string".equals(typeName)) {
                                Node attribute = node.getAttributes().getNamedItem("name");
                                if (attribute != null && attribute.getNodeType() == Node.ATTRIBUTE_NODE) {
                                    String key = attribute.getNodeValue();
                                    if (key != null && key.length() > 0) {
                                        String value = node.getTextContent();
                                        metadataMap.put(key, value);
                                        // debug
                                        //System.out.println(key + "=" + value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        logger.log(Level.WARNING, "Error obtaining warcinfo", e);
    } catch (XPathExpressionException e) {
        logger.log(Level.WARNING, "Error obtaining metadata items", e);
    }

    // add fields from harvesInfo.xml version 0.4
    /*
     * <harvestInfo> <version>0.4</version> <jobId>1</jobId> <priority>HIGHPRIORITY</priority>
     * <harvestNum>0</harvestNum> <origHarvestDefinitionID>1</origHarvestDefinitionID>
     * <maxBytesPerDomain>500000000</maxBytesPerDomain> <maxObjectsPerDomain>2000</maxObjectsPerDomain>
     * <orderXMLName>default_orderxml</orderXMLName>
     * <origHarvestDefinitionName>netarkivet</origHarvestDefinitionName> <scheduleName>Once_a_week</scheduleName>
     * <harvestFilenamePrefix>1-1</harvestFilenamePrefix> <jobSubmitDate>Some date</jobSubmitDate>
     * <performer>undefined</performer> </harvestInfo>
     */
    String netarchiveSuiteComment = "#added by NetarchiveSuite "
            + dk.netarkivet.common.Constants.getVersionString();
    ANVLRecord recordNAS = new ANVLRecord(7);

    if (metadataMap != null) {
        // Add the data from the metadataMap to the WarcInfoRecord.
        recordNAS.addLabelValue(HARVESTINFO_VERSION, (String) metadataMap.get(HARVESTINFO_VERSION));
        recordNAS.addLabelValue(HARVESTINFO_JOBID, (String) metadataMap.get(HARVESTINFO_JOBID));
        recordNAS.addLabelValue(HARVESTINFO_CHANNEL, (String) metadataMap.get(HARVESTINFO_CHANNEL));
        recordNAS.addLabelValue(HARVESTINFO_HARVESTNUM, (String) metadataMap.get(HARVESTINFO_HARVESTNUM));
        recordNAS.addLabelValue(HARVESTINFO_ORIGHARVESTDEFINITIONID,
                (String) metadataMap.get(HARVESTINFO_ORIGHARVESTDEFINITIONID));
        recordNAS.addLabelValue(HARVESTINFO_MAXBYTESPERDOMAIN,
                (String) metadataMap.get(HARVESTINFO_MAXBYTESPERDOMAIN));

        recordNAS.addLabelValue(HARVESTINFO_MAXOBJECTSPERDOMAIN,
                (String) metadataMap.get(HARVESTINFO_MAXOBJECTSPERDOMAIN));
        recordNAS.addLabelValue(HARVESTINFO_ORDERXMLNAME, (String) metadataMap.get(HARVESTINFO_ORDERXMLNAME));
        recordNAS.addLabelValue(HARVESTINFO_ORIGHARVESTDEFINITIONNAME,
                (String) metadataMap.get(HARVESTINFO_ORIGHARVESTDEFINITIONNAME));

        if (metadataMap.containsKey((HARVESTINFO_SCHEDULENAME))) {
            recordNAS.addLabelValue(HARVESTINFO_SCHEDULENAME,
                    (String) metadataMap.get(HARVESTINFO_SCHEDULENAME));
        }
        recordNAS.addLabelValue(HARVESTINFO_HARVESTFILENAMEPREFIX,
                (String) metadataMap.get(HARVESTINFO_HARVESTFILENAMEPREFIX));

        recordNAS.addLabelValue(HARVESTINFO_JOBSUBMITDATE, (String) metadataMap.get(HARVESTINFO_JOBSUBMITDATE));

        if (metadataMap.containsKey(HARVESTINFO_PERFORMER)) {
            recordNAS.addLabelValue(HARVESTINFO_PERFORMER, (String) metadataMap.get(HARVESTINFO_PERFORMER));
        }

        if (metadataMap.containsKey(HARVESTINFO_AUDIENCE)) {
            recordNAS.addLabelValue(HARVESTINFO_AUDIENCE, (String) metadataMap.get(HARVESTINFO_AUDIENCE));
        }
    } else {
        logger.log(Level.SEVERE, "Error missing metadata");
    }

    // really ugly to return as string, when it may just be merged with
    // a couple other fields at write time, but changing would require
    // larger refactoring
    return record.toString() + netarchiveSuiteComment + "\n" + recordNAS.toString();
}

From source file:net.cit.tetrad.dao.management.impl.MainDaoImpl.java

private String getServerName() {
    String hostname = "";
    try {/*from ww w  .  j a  va  2s  . co m*/
        InetAddress addr = InetAddress.getLocalHost();
        // Get hostname
        hostname = addr.getHostName();
        log.info("no error hostname:" + hostname);
    } catch (UnknownHostException e) {
        log.error(e, e);
        try {
            // Get hostname by textual representation of IP address
            InetAddress addr = InetAddress.getByName("127.0.0.1");
            // /[127.0.0.1 is always localhost -dmw]/

            // Get the host name from the address
            hostname = addr.getHostName();

            // Get canonical host name
            String hostnameCanonical = addr.getCanonicalHostName();
            log.info("hostname:" + hostname + " || hostnameCanonical:" + hostnameCanonical);
        } catch (UnknownHostException e2) {
            // handle exception
            log.error(e2, e2);
        }
    }
    return hostname;
}

From source file:com.jaspersoft.jasperserver.war.xmla.XmlaServletImpl.java

public void init(ServletConfig config) throws ServletException {
    ServletContext servletContext = config.getServletContext();

    // TODO it is meaningless to generate URLs here, but the XMLServlet requires it
    // Looks like XML/A clients ignore the URL
    try {//from   ww w  .j  a va 2  s.c  o m
        InetAddress local = InetAddress.getLocalHost();

        // We can override the default protocol and port with servlet init parameters

        String defaultProtocol = servletContext.getInitParameter("defaultProtocol");
        if (defaultProtocol == null || defaultProtocol.trim().length() == 0) {
            defaultProtocol = "http";
        }

        String defaultPort = servletContext.getInitParameter("defaultPort");
        if (defaultPort == null || defaultPort.trim().length() == 0) {
            defaultPort = "-1";
        }
        int port = Integer.parseInt(defaultPort);

        URL root = servletContext.getResource("/");
        // Looks like the path will be /localhost/webapp

        int pastHost = root.getPath().indexOf("/", 1);
        String path = root.getPath().substring(pastHost, root.getPath().length());

        SERVER_URL = (new URL(defaultProtocol, local.getCanonicalHostName(), port, path)).toString() + "xmla";
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    super.init(config);
}

From source file:org.apache.hadoop.hive.llap.LlapBaseInputFormat.java

private ServiceInstance getServiceInstanceForHost(LlapRegistryService registryService, String host)
        throws IOException {
    InetAddress address = InetAddress.getByName(host);
    ServiceInstanceSet instanceSet = registryService.getInstances();
    ServiceInstance serviceInstance = null;

    // The name used in the service registry may not match the host name we're using.
    // Try hostname/canonical hostname/host address

    String name = address.getHostName();
    LOG.info("Searching service instance by hostname " + name);
    serviceInstance = selectServiceInstance(instanceSet.getByHost(name));
    if (serviceInstance != null) {
        return serviceInstance;
    }/*from  ww  w .j  a  v a  2s.co m*/

    name = address.getCanonicalHostName();
    LOG.info("Searching service instance by canonical hostname " + name);
    serviceInstance = selectServiceInstance(instanceSet.getByHost(name));
    if (serviceInstance != null) {
        return serviceInstance;
    }

    name = address.getHostAddress();
    LOG.info("Searching service instance by address " + name);
    serviceInstance = selectServiceInstance(instanceSet.getByHost(name));
    if (serviceInstance != null) {
        return serviceInstance;
    }

    return serviceInstance;
}

From source file:org.archive.modules.writer.WARCWriterProcessor.java

public List<String> getMetadata() {
    if (cachedMetadata != null) {
        return cachedMetadata;
    }/*  w  w  w.  j a v  a  2 s .co  m*/
    ANVLRecord record = new ANVLRecord();
    record.addLabelValue("software", "Heritrix/" + ArchiveUtils.VERSION + " http://crawler.archive.org");
    try {
        InetAddress host = InetAddress.getLocalHost();
        record.addLabelValue("ip", host.getHostAddress());
        record.addLabelValue("hostname", host.getCanonicalHostName());
    } catch (UnknownHostException e) {
        logger.log(Level.WARNING, "unable top obtain local crawl engine host", e);
    }

    // conforms to ISO 28500:2009 as of May 2009
    // as described at http://bibnum.bnf.fr/WARC/ 
    // latest draft as of November 2008
    record.addLabelValue("format", "WARC File Format 1.0");
    record.addLabelValue("conformsTo", "http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf");

    // Get other values from metadata provider

    CrawlMetadata provider = getMetadataProvider();

    addIfNotBlank(record, "operator", provider.getOperator());
    addIfNotBlank(record, "publisher", provider.getOrganization());
    addIfNotBlank(record, "audience", provider.getAudience());
    addIfNotBlank(record, "isPartOf", provider.getJobName());
    // TODO: make date match 'job creation date' as in Heritrix 1.x
    // until then, leave out (plenty of dates already in WARC 
    // records
    //            String rawDate = provider.getBeginDate();
    //            if(StringUtils.isNotBlank(rawDate)) {
    //                Date date;
    //                try {
    //                    date = ArchiveUtils.parse14DigitDate(rawDate);
    //                    addIfNotBlank(record,"created",ArchiveUtils.getLog14Date(date));
    //                } catch (ParseException e) {
    //                    logger.log(Level.WARNING,"obtaining warc created date",e);
    //                }
    //            }
    addIfNotBlank(record, "description", provider.getDescription());
    addIfNotBlank(record, "robots", provider.getRobotsPolicyName().toLowerCase());

    addIfNotBlank(record, "http-header-user-agent", provider.getUserAgent());
    addIfNotBlank(record, "http-header-from", provider.getOperatorFrom());

    // really ugly to return as List<String>, but changing would require 
    // larger refactoring
    return Collections.singletonList(record.toString());
}

From source file:ws.argo.DemoWebClient.Browser.BrowserController.java

/**
 * Return the ip info of where the web host lives that supports the browser
 * app./*from w ww. j a v  a  2  s.  co m*/
 * 
 * @return the ip addr info
 * @throws UnknownHostException if something goes wrong
 */
@GET
@Path("/ipAddrInfo")
public String getIPAddrInfo() throws UnknownHostException {

    Properties clientProps = getPropeSenderProps();

    StringBuffer buf = new StringBuffer();

    InetAddress localhost = null;
    NetworkInterface ni = null;
    try {
        localhost = InetAddress.getLocalHost();
        LOGGER.debug("Network Interface name not specified.  Using the NI for localhost "
                + localhost.getHostAddress());
        ni = NetworkInterface.getByInetAddress(localhost);
    } catch (UnknownHostException | SocketException e) {
        LOGGER.error("Error occured dealing with network interface name lookup ", e);

    }

    buf.append("<p>").append("<span style='color: red'> IP Address: </span>")
            .append(localhost.getHostAddress());
    buf.append("<span style='color: red'> Host name: </span>").append(localhost.getCanonicalHostName());
    if (ni == null) {
        buf.append("<span style='color: red'> Network Interface is NULL </span>");
    } else {
        buf.append("<span style='color: red'> Network Interface name: </span>").append(ni.getDisplayName());
    }
    buf.append("</p><p>");
    buf.append("Sending probes to " + respondToAddresses.size() + " addresses -  ");
    for (ProbeRespondToAddress rta : respondToAddresses) {
        buf.append("<span style='color: red'> Probe to: </span>")
                .append(rta.respondToAddress + ":" + rta.respondToPort);
    }
    buf.append("</p>");

    return buf.toString();
}

From source file:edu.uci.ics.asterix.aoya.AsterixApplicationMaster.java

/**
 * Determines whether or not a container is the one on which the CC should reside
 * //from   ww w.j a  v  a 2s  .  c  o  m
 * @param c
 *            The container in question
 * @return True if the container should have the CC process on it, false otherwise.
 */
boolean containerIsCC(Container c) {
    String containerHost = c.getNodeId().getHost();
    try {
        InetAddress containerIp = InetAddress.getByName(containerHost);
        LOG.info(containerIp.getCanonicalHostName());
        InetAddress ccIp = InetAddress.getByName(cC.getClusterIp());
        LOG.info(ccIp.getCanonicalHostName());
        return containerIp.getCanonicalHostName().equals(ccIp.getCanonicalHostName());
    } catch (UnknownHostException e) {
        return false;
    }
}

From source file:udpserver.UDPui.java

private void receiveUDP() {
    countSeparate = new ArrayList<>();
    background = new Runnable() {
        public void run() {
            try {
                serverSocket = new DatagramSocket(9876);
            } catch (SocketException ex) {
                Logger.getLogger(UDPui.class.getName()).log(Level.SEVERE, null, ex);
            }//w  w  w . j a v a2 s . c o  m
            //                while (true) {
            //                    byte[] receiveData = new byte[1024];
            //                    DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);

            //<editor-fold defaultstate="collapsed" desc="Start timer after receive a packet">
            //                    try {
            //                        serverSocket.receive(receivePacket);
            //                        series.clear();
            //                        valuePane.setText("");
            available = true;
            //                        System.out.println(available);
            //                    } catch (IOException ex) {
            //                        Logger.getLogger(UDPui.class.getName()).log(Level.SEVERE, null, ex);
            //                    }

            //                    Timer timer = new Timer();
            //                    timer.schedule(new TimerTask() {
            //                        @Override
            //                        public void run() {
            //                            available = false;
            //                            System.out.println("Finish Timer");
            //                        }
            //                    }, 1 * 1000);
            //</editor-fold>
            //                    if (!new String(receivePacket.getData(), receivePacket.getOffset(), receivePacket.getLength()).equals("")) {
            //                        int count = 1;
            //                        while (available) {
            while (true) {
                try {
                    byte[] receiveData = new byte[total_byte];
                    byte[] sendData = new byte[32];
                    DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);

                    serverSocket.receive(receivePacket);

                    String word = receivePacket.getAddress().getHostAddress();
                    System.out.println(word);

                    String message = new String(receivePacket.getData(), receivePacket.getOffset(),
                            receivePacket.getLength());
                    boolean looprun = true;

                    //                                System.out.println(message);
                    while (looprun) {
                        Integer countt = counting.get(word);
                        if (message.contains("&")) {
                            message = message.substring(message.indexOf("&") + 1);
                            //                                        count++;
                            //                                        Integer countt = counting.get(word);
                            if (countt == null) {
                                counting.put(word, 1);
                            } else {
                                counting.put(word, countt + 1);
                            }
                            //                                        System.out.println(count + ":" + message);
                        } else {
                            if (countt == null) {
                                counting.put(word, 1);
                            } else {
                                counting.put(word, countt + 1);
                            }
                            System.out.println(counting.get(word));
                            looprun = false;
                        }
                    }

                    if (message.contains("start")) {
                        if (counting.get(word) != null) {
                            counting.remove(word);
                        }
                    } else if (message.contains("end")) {
                        message = message.substring(message.indexOf("end") + 3);
                        //                                    valuePane.setCaretPosition(valuePane.getDocument().getLength());
                        //send back to mobile
                        InetAddress IPAddress = receivePacket.getAddress();
                        int port = receivePacket.getPort();
                        //                                    String capitalizedSentence = count + "";

                        String capitalizedSentence = counting.get(word) + "";
                        sendData = capitalizedSentence.getBytes();
                        DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress,
                                port);
                        serverSocket.send(sendPacket);

                        String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss")
                                .format(Calendar.getInstance().getTime());
                        String content = IPAddress.getCanonicalHostName() + "," + timeStamp + ","
                                + (counting.get(word) - 1) + "," + message;
                        saveFile(content);
                        //end send back to mobile
                        //                                    System.out.println(counting.get(word));
                        //                                    count = 1;
                        counting.remove(word);
                        //                                    break;
                    } else if (available) {

                        //<editor-fold defaultstate="collapsed" desc="check hasmap key">
                        //                                    if (hm.size() > 0 && hm.containsKey(serverSocket.getInetAddress().getHostAddress())) {
                        //                                        hm.put(foundKey, new Integer(((int) hm.get(foundKey)) + 1));
                        //                                        hm.put(serverSocket.getInetAddress().getHostAddress(), new Integer(((int) hm.get(serverSocket.getInetAddress().getHostAddress())) + 1));
                        //                                    } else {
                        //                                        hm.put(serverSocket.getInetAddress().getHostAddress(), 1);
                        //                                        hm.entrySet().add(new Map<String, Integer>.Entry<String, Integer>());
                        //                                    }
                        //</editor-fold>
                        //                                    series.add(count, Double.parseDouble(message));
                        //                                    valuePane.setText(valuePane.getText().toString() + count + ":" + message + "\n");
                        //                                    valuePane.setCaretPosition(valuePane.getDocument().getLength());
                        //                                    count++;
                    }
                } catch (IOException ex) {
                    Logger.getLogger(UDPui.class.getName()).log(Level.SEVERE, null, ex);
                    valuePane.setText(valuePane.getText().toString() + "IOException" + "\n");
                }
            }
            //                        valuePane.setText(valuePane.getText().toString() + "Out of while loop" + "\n");
            //                    }
            //                }
        }

        private void saveFile(String content) {
            try {
                File desktop = new File(System.getProperty("user.home"), "Desktop");
                File file = new File(desktop.getAbsoluteFile() + "/udp.csv");
                if (!file.exists()) {
                    file.createNewFile();
                }
                FileOutputStream fop = new FileOutputStream(file, true);
                fop.write((content + "\n").getBytes());
                fop.flush();
                fop.close();
                //                    String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss").format(Calendar.getInstance().getTime());
                //                    valuePane.setText(valuePane.getText().toString() + timeStamp + "\n");
            } catch (IOException ex) {
                Logger.getLogger(UDPui.class.getName()).log(Level.SEVERE, null, ex);
                String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss")
                        .format(Calendar.getInstance().getTime());
                valuePane.setText(valuePane.getText().toString() + timeStamp + "\n");
            }
        }
    };
    backgroundProcess = new Thread(background);
}

From source file:com.jpeterson.littles3.StorageEngine.java

/**
 * Resolves the configured host name, replacing any tokens in the configured
 * host name value.//  w w w.  j  av  a  2s. c om
 * 
 * @return The configured host name after any tokens have been replaced.
 * @see #CONFIG_HOST
 * @see #CONFIG_HOST_TOKEN_RESOLVED_LOCAL_HOST
 */
public String resolvedHost() {
    String configHost;

    configHost = configuration.getString(CONFIG_HOST);
    logger.debug("configHost: " + configHost);

    if (configHost.indexOf(CONFIG_HOST_TOKEN_RESOLVED_LOCAL_HOST) >= 0) {
        InetAddress localHost;
        String resolvedLocalHost = "localhost";

        try {
            localHost = InetAddress.getLocalHost();
            resolvedLocalHost = localHost.getCanonicalHostName();
        } catch (UnknownHostException e) {
            logger.fatal("Unable to resolve local host", e);
        }

        configHost = configHost.replace(CONFIG_HOST_TOKEN_RESOLVED_LOCAL_HOST, resolvedLocalHost);
    }

    return configHost;
}

From source file:org.apache.oozie.test.XTestCase.java

private JobConf createDFSConfig() throws UnknownHostException {
    JobConf conf = new JobConf();
    conf.set("dfs.block.access.token.enable", "false");
    conf.set("dfs.permissions", "true");
    conf.set("hadoop.security.authentication", "simple");

    //Doing this because Hadoop 1.x does not support '*' if the value is '*,127.0.0.1'
    StringBuilder sb = new StringBuilder();
    sb.append("127.0.0.1,localhost");
    for (InetAddress i : InetAddress.getAllByName(InetAddress.getLocalHost().getHostName())) {
        sb.append(",").append(i.getCanonicalHostName());
    }/*from w  ww.  j  av a 2  s .co m*/
    conf.set("hadoop.proxyuser." + getOozieUser() + ".hosts", sb.toString());

    conf.set("hadoop.proxyuser." + getOozieUser() + ".groups", getTestGroup());
    conf.set("mapred.tasktracker.map.tasks.maximum", "4");
    conf.set("mapred.tasktracker.reduce.tasks.maximum", "4");

    conf.set("hadoop.tmp.dir", "target/test-data" + "/minicluster");

    // Scheduler properties required for YARN CapacityScheduler to work
    conf.set("yarn.scheduler.capacity.root.queues", "default");
    conf.set("yarn.scheduler.capacity.root.default.capacity", "100");
    // Required to prevent deadlocks with YARN CapacityScheduler
    conf.set("yarn.scheduler.capacity.maximum-am-resource-percent", "0.5");
    // Default value is 90 - if you have low disk space, tests will fail.
    conf.set("yarn.nodemanager.disk-health-checker.max-disk-utilization-per-disk-percentage", "99");
    return conf;
}