Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login to oc right after init #11366

Merged
merged 2 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public String execute(String command) throws IOException {
}

private void obtainKeycloakPodName() throws IOException {
openShiftCliCommandExecutor.login();

// obtain name of keycloak pod
String getKeycloakPodNameCommand =
format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.commons.io.FileUtils;
import org.eclipse.che.selenium.core.provider.OpenShiftWebConsoleUrlProvider;
import org.eclipse.che.selenium.core.utils.executor.CommandExecutor;
Expand All @@ -42,6 +43,8 @@ public class OpenShiftCliCommandExecutor implements CommandExecutor {
private static final boolean IS_MAC_OS = getProperty("os.name").toLowerCase().startsWith("mac");
private static final String DEFAULT_OPENSHIFT_USERNAME = "developer";
private static final String DEFAULT_OPENSHIFT_PASSWORD = "any";
private boolean isLoggedIn;
private ReentrantLock loginLock = new ReentrantLock();

private static final Path PATH_TO_OPENSHIFT_CLI_DIRECTORY =
Paths.get(getProperty("java.io.tmpdir"));
Expand All @@ -66,17 +69,34 @@ public class OpenShiftCliCommandExecutor implements CommandExecutor {

@Override
public String execute(String command) throws IOException {
return execute(command, true);
}

private String execute(String command, boolean needToLogin) throws IOException {
if (!PATH_TO_OPENSHIFT_CLI.toFile().exists()) {
downloadOpenShiftCli();
}

if (needToLogin && !isLoggedIn) {
loginLock.lock();
try {
login();
isLoggedIn = true;
} catch (IOException e) {
isLoggedIn = false;
throw e;
} finally {
loginLock.unlock();
}
}

String openShiftCliCommand = format("%s %s", PATH_TO_OPENSHIFT_CLI, command);

return processAgent.process(openShiftCliCommand);
}

/** Logs into OpensShift as a regular user */
public void login() throws IOException {
private void login() throws IOException {
String loginToOpenShiftCliCommand;
if (openShiftToken != null) {
loginToOpenShiftCliCommand =
Expand All @@ -92,7 +112,7 @@ public void login() throws IOException {
openShiftPassword != null ? openShiftPassword : DEFAULT_OPENSHIFT_PASSWORD);
}

execute(loginToOpenShiftCliCommand);
execute(loginToOpenShiftCliCommand, false);
}

private void downloadOpenShiftCli() throws IOException {
Expand Down