Blob Blame History Raw
From c9ec977d948d13bf46a6abcd9dd19eb2335c307f Mon Sep 17 00:00:00 2001
From: Lubomir Rintel <lubo.rintel@gooddata.com>
Date: Thu, 16 Aug 2012 16:27:45 +0200
Subject: [PATCH 07/10] Remove FTP support, it should not be used

---
 .../gooddata/integration/ftp/GdcFTPApiWrapper.java | 240 ---------------------
 doc/README.md                                      |   2 +-
 doc/architecture.dot                               |   2 +-
 3 files changed, 2 insertions(+), 242 deletions(-)
 delete mode 100644 backend/src/main/java/com/gooddata/integration/ftp/GdcFTPApiWrapper.java

diff --git a/backend/src/main/java/com/gooddata/integration/ftp/GdcFTPApiWrapper.java b/backend/src/main/java/com/gooddata/integration/ftp/GdcFTPApiWrapper.java
deleted file mode 100644
index ffc862b..0000000
--- a/backend/src/main/java/com/gooddata/integration/ftp/GdcFTPApiWrapper.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Copyright (c) 2009, GoodData Corporation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- *     * Redistributions of source code must retain the above copyright notice, this list of conditions and
- *        the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- *        and the following disclaimer in the documentation and/or other materials provided with the distribution.
- *     * Neither the name of the GoodData Corporation nor the names of its contributors may be used to endorse
- *        or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package com.gooddata.integration.ftp;
-
-import com.gooddata.exception.GdcUploadErrorException;
-import com.gooddata.integration.datatransfer.GdcDataTransferAPI;
-import com.gooddata.integration.rest.configuration.NamePasswordConfiguration;
-import com.gooddata.util.FileUtil;
-import org.apache.commons.net.ftp.FTPClient;
-import org.apache.commons.net.ftp.FTPReply;
-import org.apache.commons.net.ftp.FTPSClient;
-import org.apache.log4j.Logger;
-
-import java.io.*;
-import java.security.NoSuchAlgorithmException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * GoodData FTP API Java wrapper
- *
- * @author zd <zd@gooddata.com>
- * @version 1.0
- */
-public class GdcFTPApiWrapper implements GdcDataTransferAPI {
-
-    private static Logger l = Logger.getLogger(GdcFTPApiWrapper.class);
-
-    protected static final String DEFAULT_ARCHIVE_NAME = "upload.zip";
-
-    protected FTPClient client;
-    protected NamePasswordConfiguration config;
-
-    /**
-     * Constructs the GoodData FTP API Java wrapper
-     *
-     * @param config NamePasswordConfiguration object with the GDC name and password configuration
-     */
-    public GdcFTPApiWrapper(NamePasswordConfiguration config) {
-        this.config = config;
-        if (config.getProtocol().equals("ftps")) {
-            try {
-                client = new FTPSClient();
-            } catch (NoSuchAlgorithmException e) {
-                throw new GdcUploadErrorException("Failed to initialize secure FTP client");
-            }
-        } else {
-            l.debug("Using insecure FTP transfer");
-            client = new FTPClient();
-        }
-    }
-
-    /**
-     * FTP transfers a local directory to the remote GDC FTP server
-     *
-     * @param archiveName the name of the ZIP archive that is going to be transferred
-     * @throws IOException in case of IO issues
-     */
-    public void transferDir(String archiveName) throws IOException {
-        l.debug("Transfering archive " + archiveName);
-        try {
-            File file = new File(archiveName);
-            String dir = file.getName().split("\\.")[0];
-            client.connect(config.getGdcHost());
-            if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                client.enterLocalPassiveMode();
-                if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                    client.login(config.getUsername(), config.getPassword());
-                    if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                        client.makeDirectory(dir);
-                        if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                            client.changeWorkingDirectory(dir);
-                            if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                                client.setFileType(FTPClient.BINARY_FILE_TYPE);
-                                if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                                    client.storeFile(file.getName(), new FileInputStream(file));
-                                    if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                                        client.rename(file.getName(), DEFAULT_ARCHIVE_NAME);
-                                        if (!FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                                            l.debug("Can't change the file's name: server="
-                                                    + config.getGdcHost() + ", file=" + file.getName() + ", " + clientReply(client));
-                                            throw new GdcUploadErrorException("Can't change the file's name: server="
-                                                    + config.getGdcHost() + ", file=" + file.getName() + ", " + clientReply(client));
-                                        }
-                                    } else {
-                                        l.debug("Can't copy file to the FTP: server="
-                                                + config.getGdcHost() + ", file=" + file.getName() + ", " + clientReply(client));
-                                        throw new GdcUploadErrorException("Can't copy file to the FTP: server="
-                                                + config.getGdcHost() + ", file=" + file.getName() + ", " + clientReply(client));
-                                    }
-                                } else {
-                                    l.debug("Can't set the BINARY file transfer: server="
-                                            + config.getGdcHost() + ", " + clientReply(client));
-                                    throw new GdcUploadErrorException("Can't set the BINARY file transfer: server="
-                                            + config.getGdcHost() + ", " + clientReply(client));
-                                }
-                            } else {
-                                l.debug("Can't cd to the '" + dir + "' directory: server="
-                                        + config.getGdcHost() + ", " + clientReply(client));
-                                throw new GdcUploadErrorException("Can't cd to the '" + dir + "' directory: server="
-                                        + config.getGdcHost() + ", " + clientReply(client));
-                            }
-                        } else {
-                            l.debug("Can't create the '" + dir + "' directory: server="
-                                    + config.getGdcHost() + ", " + clientReply(client));
-                            throw new GdcUploadErrorException("Can't create the '" + dir + "' directory: server="
-                                    + config.getGdcHost() + ", " + clientReply(client));
-                        }
-                        client.logout();
-                    } else {
-                        l.debug("Can't FTP login: server=" + config.getGdcHost()
-                                + ", username=" + config.getUsername() + ", " + clientReply(client));
-                        throw new GdcUploadErrorException("Can't FTP login: server=" + config.getGdcHost()
-                                + ", username=" + config.getUsername() + ", " + clientReply(client));
-                    }
-                } else {
-                    l.debug("Can't set FTP PASV mode: server=" + config.getGdcHost()
-                            + ", username=" + config.getUsername() + ", " + clientReply(client));
-                    throw new GdcUploadErrorException("Can't set FTP PASV mode: server=" + config.getGdcHost()
-                            + ", username=" + config.getUsername() + ", " + clientReply(client));
-                }
-            } else {
-                l.debug("Can't FTP connect: server=" + config.getGdcHost() + ", " + clientReply(client));
-                throw new GdcUploadErrorException("Can't FTP connect: server=" + config.getGdcHost() + ", " + clientReply(client));
-            }
-        } finally {
-            if (client.isConnected()) {
-                try {
-                    client.disconnect();
-                } catch (IOException ioe) {
-                    // do nothing
-                }
-            }
-        }
-        l.debug("Transferred archive " + archiveName);
-    }
-
-    /**
-     * GET the transfer logs from the FTP server
-     *
-     * @param remoteDir the primary transfer directory that contains the logs
-     * @return Map with the log name and content
-     * @throws IOException in case of IO issues
-     */
-    public Map<String, String> getTransferLogs(String remoteDir) throws IOException {
-        l.debug("Retrieveing transfer logs.");
-        Map<String, String> result = new HashMap<String, String>();
-        try {
-            client.connect(config.getGdcHost());
-            if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                client.enterLocalPassiveMode();
-                client.login(config.getUsername(), config.getPassword());
-                if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                    client.changeWorkingDirectory(remoteDir);
-                    if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                        client.setFileType(FTPClient.ASCII_FILE_TYPE);
-                        if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                            String[] files = client.listNames();
-                            for (String file : files) {
-                                if (file.endsWith(".log")) {
-                                    ByteArrayOutputStream logContent = new ByteArrayOutputStream();
-                                    InputStream in = client.retrieveFileStream(file);
-                                    FileUtil.copy(in, logContent);
-                                    boolean st = client.completePendingCommand();
-                                    if (!st || !FTPReply.isPositiveCompletion(client.getReplyCode())) {
-                                        l.debug("Can't retrieve log file: server="
-                                                + config.getGdcHost() + ", file=" + file + ", " + clientReply(client));
-                                        throw new GdcUploadErrorException("Can't retrieve log file: server="
-                                                + config.getGdcHost() + ", file=" + file + ", " + clientReply(client));
-                                    }
-                                    result.put(file, new String(logContent.toByteArray()));
-                                }
-                            }
-                        } else {
-                            l.debug("Can't set the ASCII file transfer: server="
-                                    + config.getGdcHost() + ", " + clientReply(client));
-                            throw new GdcUploadErrorException("Can't set the ASCII file transfer: server="
-                                    + config.getGdcHost() + ", " + clientReply(client));
-                        }
-                    } else {
-                        l.debug("Can't cd to the '" + remoteDir + "' directory: server="
-                                + config.getGdcHost() + ", " + clientReply(client));
-                        throw new GdcUploadErrorException("Can't cd to the '" + remoteDir + "' directory: server="
-                                + config.getGdcHost() + ", " + clientReply(client));
-                    }
-                    client.logout();
-                } else {
-                    l.debug("Can't FTP login: server=" + config.getGdcHost()
-                            + ", username=" + config.getUsername() + ", " + clientReply(client));
-                    throw new GdcUploadErrorException("Can't FTP login: server=" + config.getGdcHost()
-                            + ", username=" + config.getUsername() + ", " + clientReply(client));
-                }
-            } else {
-                l.debug("Can't FTP connect: server=" + config.getGdcHost() + ", " + clientReply(client));
-                throw new GdcUploadErrorException("Can't FTP connect: server=" + config.getGdcHost() + ", " + clientReply(client));
-            }
-        } finally {
-            if (client.isConnected()) {
-                try {
-                    client.disconnect();
-                } catch (IOException ioe) {
-                    // do nothing
-                }
-            }
-        }
-        l.debug("Transfer logs retrieved.");
-        return result;
-    }
-
-    /**
-     * gets client reply
-     *
-     * @param client ftp client
-     * @return client reply
-     */
-    private String clientReply(FTPClient client) {
-        return client.getReplyString() + " (code: " + client.getReplyCode() + ")";
-    }
-}
diff --git a/doc/README.md b/doc/README.md
index 1ccfff1..8f2627c 100644
--- a/doc/README.md
+++ b/doc/README.md
@@ -16,6 +16,6 @@ The framework contains following components:
 	5. package and transfer the data to the GoodData project.
 	
 3. *GdcRESTApiWrapper* that is a communication stub that wraps the GoodData HTTP API in Java. This class de-facto translates the Java calls to the invocations of the GoodData HTTP API. The *GdcRESTApiWrapper* returns few info structures that describe the GoodData project, Data Loading Interface (DLI), DLI parts etc.
-4. *GdcFTPApiWrapper* that is a communication stub that wraps the GoodData FTP API in Java. This class takes care of the transfer of the data package to a secure private space on GoodData servers.
+4. *GdcWebDavApiWrapper* that is a communication stub that wraps the GoodData staging area access API in Java. This class takes care of the transfer of the data package to a secure private space on GoodData servers.
 5. *Connector Backend* performs the data transformation. The backend is implemented in the Derby SQL (embedded, low performance) and MySQL (needs installation, improves performance) databases. The connector backends transform the incoming data to the [3NF](http://en.wikipedia.org/wiki/Third_normal_form)
 6. *MAQLGenerator* generates the [MAQL DDL](http://developer.gooddata.com/reference/maql/maql-ddl) script that creates the GoodData LDM
diff --git a/doc/architecture.dot b/doc/architecture.dot
index 1f36f35..98898ca 100755
--- a/doc/architecture.dot
+++ b/doc/architecture.dot
@@ -8,7 +8,7 @@ digraph GoodDataCL {
 	JdbcConnector  -> AbstractConnector;
 	CsvConnector  -> AbstractConnector;	
 	AbstractConnector -> GdcRestAPIWrapper;
-	AbstractConnector -> GdcFtpAPIWrapper;
+	AbstractConnector -> GdcWebDavApiWrapper;
 	AbstractConnector -> MySqlConnectorBackend;
 	AbstractConnector -> DerbyConnectorBackend;
 	AbstractConnector -> MAQLGenerator;
-- 
1.8.3.1