Search in sources :

Example 1 with OpenShiftToolsException

use of org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException in project jbosstools-openshift by jbosstools.

the class PublishChangesTest method removeAdapterAndApplication.

@AfterClass
public static void removeAdapterAndApplication() {
    try {
        new WaitWhile(new JobIsRunning(), TimePeriod.LONG);
        new ServerAdapter(Version.OPENSHIFT3, "eap-app", "Service").delete();
    } catch (OpenShiftToolsException ex) {
    // do nothing, adapter does not exists
    }
    new ProjectExplorer().getProject(PROJECT_NAME).delete(false);
    TestUtils.cleanupGitFolder(new File(GIT_REPO_DIRECTORY));
}
Also used : ProjectExplorer(org.eclipse.reddeer.eclipse.ui.navigator.resources.ProjectExplorer) ServerAdapter(org.jboss.tools.openshift.reddeer.view.resources.ServerAdapter) WaitWhile(org.eclipse.reddeer.common.wait.WaitWhile) JobIsRunning(org.eclipse.reddeer.workbench.core.condition.JobIsRunning) File(java.io.File) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException) AfterClass(org.junit.AfterClass)

Example 2 with OpenShiftToolsException

use of org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException in project jbosstools-openshift by jbosstools.

the class OpenShiftCommandLineToolsRequirement method downloadArchive.

private String downloadArchive(String downloadLink) {
    if (StringUtils.isEmpty(downloadLink)) {
        throw new OpenShiftToolsException("Cannot download OpenShift binary. No download known\n");
    }
    String fileName = null;
    try {
        URL downloadUrl = new URL(downloadLink);
        fileName = getFileName(downloadUrl.getPath());
        if (new File(fileName).exists()) {
            LOGGER.info(fileName + " already exists, it will not be downloaded");
            return fileName;
        }
        try (FileOutputStream fileOutputStream = new FileOutputStream(fileName);
            ReadableByteChannel readableByteChannel = Channels.newChannel(downloadUrl.openStream())) {
            LOGGER.info("Downloading OpenShift binary");
            fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
        } catch (IOException ex) {
            // clean up after unsuccessful downloading
            deleteOnPathIfExists(fileName);
            throw new OpenShiftToolsException("Cannot download OpenShift binary\n" + ex.getMessage());
        }
    } catch (MalformedURLException e) {
        throw new OpenShiftToolsException(NLS.bind("Could not download \"{0}\". Invalid url", downloadLink));
    }
    return fileName;
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) MalformedURLException(java.net.MalformedURLException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException) URL(java.net.URL)

Example 3 with OpenShiftToolsException

use of org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException in project jbosstools-openshift by jbosstools.

the class OpenShiftConnectionRequirement method fulfill.

@Override
public void fulfill() {
    String server = TestUtils.getValueOrDefault(connectionSpec.server(), DatastoreOS3.SERVER);
    String username = TestUtils.getValueOrDefault(connectionSpec.username(), DatastoreOS3.USERNAME);
    String password = TestUtils.getValueOrDefault(connectionSpec.password(), DatastoreOS3.PASSWORD);
    String token = TestUtils.getValueOrDefault(connectionSpec.token(), DatastoreOS3.TOKEN);
    try {
        ConnectionURL url;
        if (StringUtils.isNotEmpty(password) && StringUtils.isNotEmpty(username)) {
            url = getConnectionURL(username, server);
        } else {
            url = getConnectionURL(server);
        }
        Connection connection = ConnectionsRegistrySingleton.getInstance().getByUrl(url, Connection.class);
        if (connection == null) {
            LOGGER.debug(NLS.bind("No connection for {0} found. Creating a new one.", url));
            connection = createConnection(server, username, password, token);
            ConnectionsRegistrySingleton.getInstance().add(connection);
        }
        LOGGER.debug(NLS.bind("Connecting to OpenShift 3 server at {0}", url));
        connection.connect();
        this.connection = connection;
    } catch (UnsupportedEncodingException | MalformedURLException e) {
        throw new OpenShiftToolsException(NLS.bind("Could not create connection for {0} : {1}", server, e));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) RequiredBasicConnection(org.jboss.tools.openshift.reddeer.requirement.OpenShiftConnectionRequirement.RequiredBasicConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)

Example 4 with OpenShiftToolsException

use of org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException in project jbosstools-openshift by jbosstools.

the class FileHelper method extractTarGz.

public static void extractTarGz(File archive, File outputDirectory) {
    InputStream inputStream = null;
    try {
        logger.info("Opening stream to gzip archive");
        inputStream = new GzipCompressorInputStream(new FileInputStream(archive));
    } catch (IOException ex) {
        throw new OpenShiftToolsException("Exception occured while processing tar.gz file.\n" + ex.getMessage());
    }
    logger.info("Opening stream to tar archive");
    BufferedOutputStream outputStream = null;
    TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(inputStream);
    TarArchiveEntry currentEntry = null;
    try {
        while ((currentEntry = tarArchiveInputStream.getNextTarEntry()) != null) {
            if (currentEntry.isDirectory()) {
                logger.info("Creating directory: " + currentEntry.getName());
                createDirectory(new File(outputDirectory, currentEntry.getName()));
            } else {
                File outputFile = new File(outputDirectory, currentEntry.getName());
                if (!outputFile.getParentFile().exists()) {
                    logger.info("Creating directory: " + outputFile.getParentFile());
                    createDirectory(outputFile.getParentFile());
                }
                outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
                logger.info("Extracting file: " + currentEntry.getName());
                copy(tarArchiveInputStream, outputStream, (int) currentEntry.getSize());
                outputStream.close();
                outputFile.setExecutable(true);
                outputFile.setReadable(true);
                outputFile.setWritable(true);
            }
        }
    } catch (IOException e) {
        throw new OpenShiftToolsException("Exception occured while processing tar.gz file.\n" + e.getMessage());
    } finally {
        try {
            tarArchiveInputStream.close();
        } catch (Exception ex) {
        }
        try {
            outputStream.close();
        } catch (Exception ex) {
        }
    }
}
Also used : GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) BufferedInputStream(java.io.BufferedInputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) FileInputStream(java.io.FileInputStream) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File) ZipFile(java.util.zip.ZipFile) FileInputStream(java.io.FileInputStream) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException) IOException(java.io.IOException)

Example 5 with OpenShiftToolsException

use of org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException in project jbosstools-openshift by jbosstools.

the class OpenShiftCommandLineToolsRequirement method fulfill.

@Override
public void fulfill() {
    if (!binary.ocExists()) {
        if (!OCBinaryFile.get().getFile().exists()) {
            String url = getDownloadLink(binary.latestOC());
            LOGGER.info("OC binary will be downloaded from " + url);
            File downloadedOCBinary = downloadAndExtractOpenShiftClient(url);
            // windows has problem with previously defined symlinks, we will used copied oc from extracted
            // createSymLink method was used
            this.pathToOC = copyOCFromExtractedFolder(downloadedOCBinary);
        } else {
            this.pathToOC = OCBinaryFile.get().getFile().getAbsolutePath();
            LOGGER.info("Binary is already downloaded at " + getPathToOC());
        }
    } else {
        LOGGER.info("External OC binary will be used");
        File oc = new File(binary.pathToOC());
        if (oc.exists()) {
            LOGGER.info("OC binary is at " + oc.getAbsolutePath());
            this.pathToOC = oc.getAbsolutePath();
        } else {
            throw new OpenShiftToolsException("Given path to OC binary does not exist: " + binary.pathToOC());
        }
    }
    if (binary.setOCInPrefs()) {
        setOCToPreferences(getPathToOC());
    }
}
Also used : File(java.io.File) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)

Aggregations

OpenShiftToolsException (org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)16 File (java.io.File)7 IOException (java.io.IOException)4 MalformedURLException (java.net.MalformedURLException)3 WaitUntil (org.eclipse.reddeer.common.wait.WaitUntil)3 ShellIsAvailable (org.eclipse.reddeer.swt.condition.ShellIsAvailable)3 ServerAdapter (org.jboss.tools.openshift.reddeer.view.resources.ServerAdapter)3 FileOutputStream (java.io.FileOutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ZipFile (java.util.zip.ZipFile)2 WaitTimeoutExpiredException (org.eclipse.reddeer.common.exception.WaitTimeoutExpiredException)2 WaitWhile (org.eclipse.reddeer.common.wait.WaitWhile)2 ProjectExplorer (org.eclipse.reddeer.eclipse.ui.navigator.resources.ProjectExplorer)2 OkButton (org.eclipse.reddeer.swt.impl.button.OkButton)2 DefaultShell (org.eclipse.reddeer.swt.impl.shell.DefaultShell)2 JobIsRunning (org.eclipse.reddeer.workbench.core.condition.JobIsRunning)2 ConnectionURL (org.jboss.tools.openshift.common.core.connection.ConnectionURL)2 After (org.junit.After)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1