Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

che-starter #254: Cleanup & Refactoring - removing all toggle / workspace migration / OpenShift specific code #256

Merged
merged 1 commit into from
Jan 23, 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<org.apache.commons.lang.version>3.5</org.apache.commons.lang.version>
<swagger.version>2.6.1</swagger.version>
<licenseMavenPluginVersion>1.11</licenseMavenPluginVersion>
<vertx.server.version>v1.5</vertx.server.version>
<vertx.server.version>v1.7</vertx.server.version>
<logstash.logback.encoder.version>4.9</logstash.logback.encoder.version>
<jjwt.version>0.7.0</jjwt.version>
<unleash.client.java.version>2.1.4</unleash.client.java.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public enum CheRestEndpoints {
STOP_WORKSPACE ("/api/workspace/{id}/runtime"),
LIST_STACKS ("/api/stack?maxItems=1000"),
DELETE_PROJECT ("/project/{id}"),
SET_OAUTH_TOKEN_V1 ("/wsmaster/api/oauth/token?oauth_provider={provider}"),
SET_OAUTH_TOKEN_V2 ("/wsmaster/api/token/github"),
SET_OAUTH_TOKEN ("/wsmaster/api/token/github"),
GET_PREFERENCES ("/wsmaster/api/preferences"),
UPDATE_PREFERENCES ("/wsmaster/api/preferences");

Expand Down
114 changes: 0 additions & 114 deletions src/main/java/io/fabric8/che/starter/client/CheServerClient.java

This file was deleted.

60 changes: 31 additions & 29 deletions src/main/java/io/fabric8/che/starter/client/ProjectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
Expand All @@ -30,53 +31,54 @@
public class ProjectClient {
private static final Logger LOG = LoggerFactory.getLogger(ProjectClient.class);

@Value("${MULTI_TENANT_CHE_SERVER_URL:https://che.prod-preview.openshift.io}")
private String multiTenantCheServerURL;

@Autowired
private WorkspaceClient workspaceClient;

/**
* Delete a project from workspace. Workspace must be running to delete a
* project.
*
* @param cheServerURL
* @param workspaceName
* @param projectName
*/
public void deleteProject(String cheServerURL, Workspace workspace, String projectName, String keycloakToken) {
String wsAgentUrl = getWsAgentUrl(workspace);

String deleteProjectURL = CheRestEndpoints.DELETE_PROJECT.generateUrl(wsAgentUrl, projectName);
LOG.info("Deleting project {}", projectName);
RestTemplate template = new KeycloakRestTemplate(keycloakToken);
template.delete(deleteProjectURL);
}

@Async
public void deleteAllProjectsAndWorkspace(String cheServerURL, String workspaceName, String masterUrl, String namespace, String openShiftToken,
String keycloakToken) throws WorkspaceNotFound {
Workspace runningWorkspace = workspaceClient.getStartedWorkspace(cheServerURL, keycloakToken);
public void deleteAllProjectsAndWorkspace(String workspaceName, String keycloakToken) throws WorkspaceNotFound {
Workspace runningWorkspace = workspaceClient.getStartedWorkspace(keycloakToken);

Workspace workspaceToDelete = workspaceClient.startWorkspace(cheServerURL, workspaceName, masterUrl, namespace, openShiftToken, keycloakToken);
workspaceClient.waitUntilWorkspaceIsRunning(cheServerURL, workspaceToDelete, keycloakToken);
workspaceToDelete = workspaceClient.getWorkspaceById(cheServerURL, workspaceToDelete.getId(), keycloakToken);
Workspace workspaceToDelete = workspaceClient.startWorkspace(workspaceName, keycloakToken);
workspaceClient.waitUntilWorkspaceIsRunning(workspaceToDelete, keycloakToken);
workspaceToDelete = workspaceClient.getWorkspaceById(workspaceToDelete.getId(), keycloakToken);

List<Project> projectsToDelete = workspaceToDelete.getConfig().getProjects();
if (projectsToDelete != null && !projectsToDelete.isEmpty()) {
for (Project project : projectsToDelete) {
deleteProject(cheServerURL, workspaceToDelete, project.getName(), keycloakToken);
deleteProject(workspaceToDelete, project.getName(), keycloakToken);
}
}

workspaceClient.stopWorkspace(cheServerURL, workspaceToDelete, keycloakToken);
workspaceClient.waitUntilWorkspaceIsStopped(masterUrl, namespace, openShiftToken, cheServerURL, workspaceToDelete, keycloakToken);

workspaceClient.deleteWorkspace(cheServerURL, workspaceToDelete.getId(), keycloakToken);
workspaceClient.stopWorkspace(workspaceToDelete, keycloakToken);
workspaceClient.waitUntilWorkspaceIsStopped(workspaceToDelete, keycloakToken);
workspaceClient.deleteWorkspace(workspaceToDelete.getId(), keycloakToken);

if (runningWorkspace != null && !runningWorkspace.getConfig().getName().equals(workspaceName)) {
workspaceClient.startWorkspace(cheServerURL, runningWorkspace.getConfig().getName(), masterUrl, namespace, openShiftToken, keycloakToken);
workspaceClient.startWorkspace(runningWorkspace.getConfig().getName(), keycloakToken);

}
}

/**
* Delete a project from workspace. Workspace must be running to delete a
* project.
*
* @param workspaceName
* @param projectName
* @param keycloakToken
*/
public void deleteProject(Workspace workspace, String projectName, String keycloakToken) {
String wsAgentUrl = getWsAgentUrl(workspace);

String deleteProjectURL = CheRestEndpoints.DELETE_PROJECT.generateUrl(wsAgentUrl, projectName);
LOG.info("Deleting project {}", projectName);
RestTemplate template = new KeycloakRestTemplate(keycloakToken);
template.delete(deleteProjectURL);
}

private String getWsAgentUrl(final Workspace workspace) {
return workspace.getRuntime().getDevMachine().getRuntime().getServers().get("4401/tcp").getUrl();
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/io/fabric8/che/starter/client/StackClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.NoSuchElementException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
Expand All @@ -29,8 +30,11 @@
@Component
public class StackClient {

public List<Stack> listStacks(String cheServerUrl, String keycloakToken) {
String url = CheRestEndpoints.LIST_STACKS.generateUrl(cheServerUrl);
@Value("${MULTI_TENANT_CHE_SERVER_URL:https://che.prod-preview.openshift.io}")
private String multiTenantCheServerURL;

public List<Stack> listStacks(String keycloakToken) {
String url = CheRestEndpoints.LIST_STACKS.generateUrl(multiTenantCheServerURL);

RestTemplate template = new KeycloakRestTemplate(keycloakToken);

Expand All @@ -44,14 +48,13 @@ public List<Stack> listStacks(String cheServerUrl, String keycloakToken) {
* Gets image for specified stack ID. Throws StackNotFoundException if there is no such stack
* on the Che server.
*
* @param cheServerUrl URL of Che server
* @param stackId stack ID
* @param keycloakToken Keycloak token
* @return image name for stack
* @throws StackNotFoundException if no image name exists for such stack ID or call to Che server was not successful
*/
public Stack getStack(String cheServerUrl, String stackId, String keycloakToken) throws StackNotFoundException {
List<Stack> stacks = listStacks(cheServerUrl, keycloakToken);
public Stack getStack(String stackId, String keycloakToken) throws StackNotFoundException {
List<Stack> stacks = listStacks(keycloakToken);
if (stacks != null && !stacks.isEmpty()) {
try {
Stack stack = stacks.stream().filter(s -> stackId.equals(s.getId())).findFirst().get();
Expand Down
Loading