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));
}
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;
}
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));
}
}
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) {
}
}
}
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());
}
}
Aggregations