Skip to content

Commit

Permalink
[SP-4263 | Abhishek/Anuja] Fixed failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
anujachaitanya committed Nov 25, 2024
1 parent 2033bfd commit 788db59
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 63 deletions.
18 changes: 11 additions & 7 deletions skaha/src/main/java/org/opencadc/skaha/K8SUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public static String getHostName() {

/**
* Helps reduce string constants in many places.
* @return The Skaha namespace
*
* @return The Skaha namespace
*/
public static String getNamespace() {
return "skaha-system";
Expand All @@ -94,11 +95,13 @@ public static String getWorkloadNamespace() {

/**
* Filter out anything not in the alphanumeric or hyphen character set.
* @see <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/names/">Kubernetes Object names</a>
* @param sessionID The provided session ID.
* @param type The defined type (desktop, notebook, etc.)
* @param userID The running User's ID.
* @return String sanitized name. Never null.
*
* @param sessionID The provided session ID.
* @param type The defined type (desktop, notebook, etc.)
* @param userID The running User's ID.
* @return String sanitized name. Never null.
* @see <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/names/">Kubernetes Object
* names</a>
*/
public static String getJobName(String sessionID, String type, String userID) {
// Replace values that are NOT alphanumeric or a hyphen.
Expand Down Expand Up @@ -133,7 +136,8 @@ public static String getSessionExpiry() {

/**
* Obtain the configured default quota size in Gigabytes.
* @return integer in GB.
*
* @return integer in GB.
*/
public static String getDefaultQuota() {
return System.getenv(K8SUtil.ARC_USER_QUOTA_IN_GB_NAME);
Expand Down
4 changes: 2 additions & 2 deletions skaha/src/main/java/org/opencadc/skaha/SkahaAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ public Image getPublicImage(String imageID) {
}

/**
* It's important to use the correct constructor for the PosixMapperClient, this class will wrap the logic
* based on how the Resource ID of the POSIX mapper was set (URI or URL).
* It's important to use the correct constructor for the PosixMapperClient, this class will wrap the logic based on
* how the Resource ID of the POSIX mapper was set (URI or URL).
*/
protected static class PosixMapperConfiguration {
final URI resourceID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@
import org.opencadc.skaha.utils.CommandExecutioner;
import org.opencadc.skaha.utils.KubectlCommandBuilder;

/**
*
* @author majorb
*/
/** @author majorb */
public class DeleteAction extends SessionAction {

private static final Logger log = Logger.getLogger(DeleteAction.class);
Expand Down
38 changes: 15 additions & 23 deletions skaha/src/main/java/org/opencadc/skaha/session/PostAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@
import org.opencadc.skaha.utils.PosixCache;
import org.opencadc.skaha.utils.QueueUtil;

/**
* @author majorb
*/
/** @author majorb */
public class PostAction extends SessionAction {

// variables replaced in kubernetes yaml config files for
Expand Down Expand Up @@ -458,13 +456,13 @@ private void validateName(String name) {
}

/**
* Validate and return the session type. There exists a loophole
* Validate and return the session type. There exists a loophole
*
* @param imageID The image to validate
* @param type User-provided session type (optional), defaults to headless
* @param type User-provided session type (optional), defaults to headless
* @return The system recognized session type
* @throws ResourceNotFoundException If an image with the supplied ID cannot be found
* @throws Exception If Harbor calls fail
* @throws Exception If Harbor calls fail
*/
private String validateImage(String imageID, String type) throws Exception {
if (!StringUtil.hasText(imageID)) {
Expand Down Expand Up @@ -723,15 +721,15 @@ private String getRegistryHost(final String imageID) {
}

/**
* Attach a desktop application.
* TODO: This method requires rework. The Job Name does not use the same mechanism as the K8SUtil.getJobName()
* TODO: and will suffer the same issue(s) with invalid characters in the Kubernetes object names.
* Attach a desktop application. TODO: This method requires rework. The Job Name does not use the same mechanism as
* the K8SUtil.getJobName() TODO: and will suffer the same issue(s) with invalid characters in the Kubernetes object
* names.
*
* @param image Container image name.
* @param requestCores Requested number of cores.
* @param limitCores Max number of cores.
* @param requestRAM Requested amount of RAM in Gi.
* @param limitRAM Max amount of RAM in Gi.
* @param requestCores Requested number of cores.
* @param limitCores Max number of cores.
* @param requestRAM Requested amount of RAM in Gi.
* @param limitRAM Max amount of RAM in Gi.
* @throws Exception For any unexpected errors.
*/
public void attachDesktopApp(
Expand Down Expand Up @@ -873,16 +871,10 @@ List<PosixGroup> toGIDs(final List<GroupURI> groupURIS) throws Exception {
}

/**
* Create the image, command, args, and env sections of the job launch yaml. Example:
* <p />
* image: "${software.imageid}"
* command: ["/skaha-system/start-desktop-software.sh"]
* args: [arg1, arg2]
* env:
* - name: HOME
* value: "/cavern/home/${skaha.userid}"
* - name: SHELL
* value: "/bin/bash"
* Create the image, command, args, and env sections of the job launch yaml. Example:
*
* <p>image: "${software.imageid}" command: ["/skaha-system/start-desktop-software.sh"] args: [arg1, arg2] env: -
* name: HOME value: "/cavern/home/${skaha.userid}" - name: SHELL value: "/bin/bash"
*/
private String getHeadlessImageBundle(String image, String cmd, String args, List<String> envs) {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ static Session constructSession(String k8sOutput, final String topLevelDirectory
}

/**
* Example input is [4444 5555 6666]. Convert to an actual integer array.
* Example input is [4444 5555 6666]. Convert to an actual integer array.
*
* @param inputArray Kubernetes output of an array of integers.
* @return integer array, never null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static void execute(final String[] command, final OutputStream standardOu
* Delete, if necessary, and recreate the image pull secret for the given registry.
*
* @param registryAuth The registry credentials.
* @param secretName The name of the secret to create.
* @param secretName The name of the secret to create.
* @throws Exception If there is an error creating the secret.
*/
public static void ensureRegistrySecret(final ImageRepositoryAuth registryAuth, final String secretName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@
public class DockerDelete extends DeleteAction {

private static final Logger log = Logger.getLogger(DockerDelete.class);

@Override
public void stopSession(String userID, String sessionID) throws Exception {
// kill the session specified by sessionID
log.debug("Stopping VNC session");
String[] stopVNCCmd = new String[] {"/scripts/docker/stop-desktop.sh", userID, sessionID};
execute(stopVNCCmd);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@
import ca.nrc.cadc.util.StringUtil;

public class DockerGet extends GetAction {

private static final Logger log = Logger.getLogger(DockerGet.class);

@Override
public void listSessions() throws Exception {

String[] getVNCSessions = new String[] {"docker", "ps", "--format", "{{.Names}}\\t{{.Status}}", "--filter", "label=canfar-net-userid=" + userID};
String vncSessions = execute(getVNCSessions);

if (StringUtil.hasLength(vncSessions)) {
String[] lines = vncSessions.split("\n");
if (lines.length > 0) {
Expand Down Expand Up @@ -120,21 +120,21 @@ public void listSessions() throws Exception {
}
log.debug("No container listing output");
}

protected String parseCID(String vncName) {
String[] parts = vncName.split("_");
String sessionID = parts[parts.length - 2];
return sessionID;
}

protected String parseCURL(String vncName) throws IOException, InterruptedException {
String sessionID = parseCID(vncName);
String[] getIpCmd = new String[] {
"docker", "inspect", "--format", "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}", vncName};
String ipAddress = execute(getIpCmd);
return getVNCURL(server, sessionID, ipAddress);
}

protected String parseCName(String vncName) {
String[] parts = vncName.split("_");
return parts[parts.length - 1];
Expand Down
24 changes: 12 additions & 12 deletions skaha/src/obsolete/java/org/opencadc/arcade/docker/DockerPost.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
import ca.nrc.cadc.util.StringUtil;

public class DockerPost extends PostAction {

private static final Logger log = Logger.getLogger(DockerPost.class);

@Override
public void checkForExistingSession(String userid) throws Exception {
String[] getVNCSessions = new String[] {"docker", "ps", "--format", "{{.Names}}\\t{{.Status}}", "--filter", "label=canfar-net-userid=" + userID};
Expand All @@ -93,48 +93,48 @@ public void checkForExistingSession(String userid) throws Exception {
}
}
}

@Override
public URL createSession(String sessionID, String name) throws Exception {

String[] runNoVNCCmd = new String[] {"/scripts/docker/run-desktop.sh", userID, sessionID, name, homedir, scratchdir};
String imageID = execute(runNoVNCCmd);

// insert the user's proxy cert on the container
Subject subject = AuthenticationUtil.getCurrentSubject();
//injectProxyCert("/home", subject, userID);

String[] getIpCmd = new String[] {
"docker", "inspect", "--format", "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}", imageID};
String ipAddress = execute(getIpCmd);

// give vnc a few seconds to initialize
try {
log.debug("3 second wait for vnc initialization");
Thread.sleep(2000);
} catch (InterruptedException ignore) {
}
log.debug("wait over");

String redirectPath = super.getVNCURL(server, sessionID, ipAddress);
return new URL(redirectPath);
}

@Override
public void attachSoftware(String software, List<String> params, String targetIP) throws Exception {

confirmSoftware(software);

// only one parameter supported for now
String param = "xterm";
if (params != null && params.size() > 0) {
param = params.get(0);
}
log.debug("Using parameter: " + param);

String[] runAppCmd = new String[] {"/scripts/docker/software.sh", software, targetIP, userID, homedir, scratchdir, param};
String imageID = execute(runAppCmd);

// refresh the user's proxy cert
Subject subject = AuthenticationUtil.getCurrentSubject();
//injectProxyCert("/home", subject, userID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.when;
import static org.opencadc.skaha.utils.TestUtils.set;
import static org.opencadc.skaha.utils.TestUtils.setEnv;

import java.util.List;
import java.util.Set;
Expand All @@ -83,10 +82,7 @@
import org.opencadc.skaha.SkahaAction;
import org.opencadc.skaha.utils.RedisCache;

/**
* @author majorb
*
*/
/** @author majorb */
@RunWith(MockitoJUnitRunner.class)
public class GetActionTest {

Expand Down

0 comments on commit 788db59

Please sign in to comment.