Dipesh Raichana
Dipesh Raichana

Reputation: 1068

java.lang.IllegalArgumentException: Wrong FS: hdfs://localhost:9000 expected: file:///

I am struggling in hadoop commands for copy,delete,rename & move. I am getting following error while running copy. I have checked other similar answers too but not successful.

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Wrong FS: hdfs://localhost:9000/user/new1, expected: file:///
at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:390)
at org.apache.hadoop.fs.RawLocalFileSystem.pathToFile(RawLocalFileSystem.java:55)
at org.apache.hadoop.fs.LocalFileSystem.pathToFile(LocalFileSystem.java:61)
at org.apache.hadoop.fs.LocalFileSystem.exists(LocalFileSystem.java:51)
at org.apache.hadoop.fs.FileUtil.checkDest(FileUtil.java:355)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:211)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:163)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:1257)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:1238)
at hdfstest1.HDFSTestGUI1.copyDirectory(HDFSTestGUI1.java:710)
at hdfstest1.HDFSTestGUI1.jMenuPasteItemActionPerformed(HDFSTestGUI1.java:446)
at hdfstest1.HDFSTestGUI1.access$400(HDFSTestGUI1.java:43)
at hdfstest1.HDFSTestGUI1$5.actionPerformed(HDFSTestGUI1.java:172)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Here is my code snippet:

 //constructor
 public HDFSTestGUI1()  {
    try{
        conf1.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
        conf1.addResource(new Path("/usr/local/hadoop/conf/hdfs-site.xml"));
        initComponents();
        setIcon();
        showDate();
        showTime();
        homeBtn.doClick();
        writeBtn1.setVisible(false);
        readBtn.setVisible(false);
    } catch(Exception ex) {
         JOptionPane.showMessageDialog(this, "Exception::Please check core-site.xml config or " + ex);
    }

     //main method
    public static void main(String args[]) {
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException | InstantiationException | 
    IllegalAccessException | 
javax.swing.UnsupportedLookAndFeelException ex) {
     java.util.logging.Logger.getLogger(HDFSTestGUI1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>
    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                new HDFSTestGUI1().setVisible(true);
            } catch (Exception ex) {

  Logger.getLogger(HDFSTestGUI1.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}


private void copyDirectory(String srcPath, String destPath) {
    try {
        Path p1, p2;
        p1 = new Path(srcPath);
        p2 = new Path(destPath);
        if (p1.getFileSystem(conf1).exists(p2)) {
            fs.copyToLocalFile(p1,p2);
            JOptionPane.showMessageDialog(this, "Copied 
 Successfully");
        } else {
            JOptionPane.showMessageDialog(this, "Destination path does 
  not Exist::" + p2);
        }

    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this, ex);

Logger.getLogger(HDFSTestGUI1.class.getName()).log(Level.SEVERE, null, ex);
    }
}

core-site.xml:

<configuration>

<property>
<name>hadoop.tmp.dir</name>
<value>/app/hadoop/tmp</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000/</value>
<description>The name of the default file system.  A URI whose
scheme and authority determine the FileSystem implementation.  The
uri's scheme determines the config property (fs.SCHEME.impl) naming
the FileSystem implementation class.  The uri's authority is used to
determine the host, port, etc. for a filesystem.</description>
</property>

</configuration>

Can somebody show me the correct direction?

Upvotes: 0

Views: 3299

Answers (1)

philantrovert
philantrovert

Reputation: 10082

In the copyDirectory method, fs is un-defined. You might want to use:

FileSystem fs = FileSystem.get(conf)

conf being org.apache.hadoop.conf.Configuration object.

Upvotes: 1

Related Questions