Skip to content

Commit

Permalink
fix: many bug fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
at88mph committed Nov 7, 2024
1 parent 3f50de4 commit 1352f6a
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ HOST=(HOST)

# Callback token
TOKEN="${DESKTOP_SESSION_APP_TOKEN}"
CURL_APP_SESSION_HEADERS="--header \"x-auth-token-skaha: ${TOKEN}\""

handle_error() {
echo "$1"
Expand All @@ -19,10 +18,10 @@ get_resource_options() {
else
resources=`curl -s -L -k --header "x-auth-token-skaha: ${TOKEN}" https://(HOST)/skaha/(SKAHA_API_VERSION)/context`
fi
core_default=`echo $resources | jq .defaultCores`
core_options=`echo $resources | jq .availableCores[] | tr '\n' ' '`
ram_default=`echo $resources | jq .defaultRAM`
ram_options=`echo $resources | jq .availableRAM[] | tr '\n' ' '`
core_default=`echo $resources | jq .cores.default`
core_options=`echo $resources | jq .cores.options[] | tr '\n' ' '`
ram_default=`echo $resources | jq .memoryGB.default`
ram_options=`echo $resources | jq .memoryGB.options[] | tr '\n' ' '`
}

get_cores() {
Expand Down Expand Up @@ -90,7 +89,7 @@ prompt_user() {
if [ -z "${TOKEN}" ]; then
handle_error "[skaha] No credentials to call back to Skaha with."
else
app_id=`curl -s -L -k "${CURL_APP_SESSION_HEADERS}" -d "image=(IMAGE_ID)" --data-urlencode "param=(NAME)" https://(HOST)/skaha/(SKAHA_API_VERSION)/session/${VNC_PW}/app`
app_id=`curl -s -L -k "x-auth-token-skaha: ${TOKEN}" -d "image=(IMAGE_ID)" --data-urlencode "param=(NAME)" https://(HOST)/skaha/(SKAHA_API_VERSION)/session/${VNC_PW}/app`
fi
break
elif [[ ${yn} == "y" || ${yn} == "Y" ]]; then
Expand All @@ -102,7 +101,7 @@ prompt_user() {
if [ -z "${TOKEN}" ]; then
handle_error "[skaha] No credentials to call back to Skaha with."
else
app_id=`curl -s -L -k "${CURL_APP_SESSION_HEADERS}" -d "cores=${cores}" -d "ram=$ram" -d "image=(IMAGE_ID)" --data-urlencode "param=(NAME)" https://(HOST)/skaha/(SKAHA_API_VERSION)/session/${VNC_PW}/app`
app_id=`curl -s -L -k "x-auth-token-skaha: ${TOKEN}" -d "cores=${cores}" -d "ram=$ram" -d "image=(IMAGE_ID)" --data-urlencode "param=(NAME)" https://(HOST)/skaha/(SKAHA_API_VERSION)/session/${VNC_PW}/app`
fi
break
else
Expand Down
2 changes: 1 addition & 1 deletion deployment/helm/skaha/launch-scripts/build-menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ build_menu_item () {
echo "[skaha] Start building menu."
init
create_merged_applications_menu
curl_out=$(curl -s -k --header "x-auth-token-skaha:${TOKEN}" "https://${HOST}/skaha/${SKAHA_API_VERSION}/image?type=desktop-app")
curl_out=$(curl -s -k --header "x-auth-token-skaha: ${TOKEN}" "https://${HOST}/skaha/${SKAHA_API_VERSION}/image?type=desktop-app")
if [[ $(echo ${curl_out} | jq '[.[] | .id | length] | add') == 0 ]]; then
echo "[skaha] no desktop-app"
echo "${curl_out}"
Expand Down
36 changes: 0 additions & 36 deletions deployment/helm/skaha/skaha-config/k8s-resources.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ data:
{{ base $path }}: |
{{- tpl ($.Files.Get $path) $currContext | nindent 4 }}
{{ end }}
{{ ($.Files.Glob "skaha-config/*.properties").AsConfig | indent 2 }}
{{ ($.Files.Glob "skaha-config/*.json").AsConfig | indent 2 }}
{{- include "utils.extraConfig" (dict "extraConfigData" .Values.deployment.skaha.extraConfigData) -}}
{{- (.Files.Glob "image-cache/*").AsConfig | nindent 2 }}
7 changes: 7 additions & 0 deletions image-cache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Redis cache client for Image Listings

This builds a simple image with some formatting tools to support the image caching feature in Skaha. This image acts as a client
to a running Redis cache. See the [cache-images.sh script](https://github.com/opencadc/science-platform/blob/main/deployment/helm/skaha/image-cache/cache-images.sh) in
Skaha, which is run from _within_ this Image.

See also the [`CronJob` and initialization `Job`](https://github.com/opencadc/science-platform/blob/main/deployment/helm/skaha/templates/image-caching-cronjob.yaml) on how this image is used from a Skaha deployment.
6 changes: 6 additions & 0 deletions image-cache/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## deployable containers have a semantic and build tag
# version tag: major.minor.patch
# build version tag: timestamp
VER=0.1.0
TAGS="${VER} ${VER}-$(date -u +"%Y%m%dT%H%M%S")"
unset VER
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,12 @@
package org.opencadc.skaha;

import ca.nrc.cadc.auth.AuthMethod;
import ca.nrc.cadc.net.HttpGet;
import ca.nrc.cadc.reg.Standards;
import ca.nrc.cadc.reg.client.RegistryClient;
import ca.nrc.cadc.util.Log4jInit;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.Type;
import java.net.URL;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.security.auth.Subject;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -122,11 +115,12 @@ public DesktopAppLifecycleTest() {
public void testCreateDeleteDesktopApp() throws Exception {
Subject.doAs(userSubject, (PrivilegedExceptionAction<Void>) () -> {
// ensure that there is no active session
initialize();
SessionUtil.initializeCleanup(this.sessionURL);

// create desktop session
final String desktopSessionID = SessionUtil.createSession(this.sessionURL, "inttest" + SessionAction.SESSION_TYPE_DESKTOP,
SessionUtil.getImageOfType(SessionAction.SESSION_TYPE_DESKTOP).getId());
SessionUtil.getImageOfType(SessionAction.SESSION_TYPE_DESKTOP).getId(),
SessionAction.SESSION_TYPE_DESKTOP);

final Session desktopSession = SessionUtil.waitForSession(this.sessionURL, desktopSessionID, Session.STATUS_RUNNING);
SessionUtil.verifySession(desktopSession, SessionAction.SESSION_TYPE_DESKTOP, "inttest" + SessionAction.SESSION_TYPE_DESKTOP);
Expand Down Expand Up @@ -175,21 +169,4 @@ public void testCreateDeleteDesktopApp() throws Exception {
return null;
});
}

private void initialize() throws Exception {
List<Session> sessions = SessionUtil.getSessions(this.sessionURL);
for (Session session : sessions) {
if (session.getType().equals(SessionAction.TYPE_DESKTOP_APP)) {
// delete desktop-app
String sessionID = session.getId();
final URL desktopAppURL = new URL(sessionURL.toString() + "/" + sessionID + "/app");
SessionUtil.deleteDesktopApplicationSession(desktopAppURL, session.getAppId());
} else {
// delete session
SessionUtil.deleteSession(sessionURL, session.getId());
}
}
sessions = SessionUtil.getSessions(this.sessionURL);
Assert.assertEquals("zero sessions #1", 0, sessions.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import ca.nrc.cadc.reg.Standards;
import ca.nrc.cadc.reg.client.RegistryClient;
import ca.nrc.cadc.util.Log4jInit;

import java.net.MalformedURLException;
import java.net.URL;
import java.security.PrivilegedExceptionAction;
Expand All @@ -82,10 +81,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import java.util.concurrent.TimeUnit;
import javax.security.auth.Subject;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Assert;
Expand All @@ -98,35 +95,18 @@
*/
public class ExpiryTimeRenewalTest {

private static final Logger log = Logger.getLogger(ExpiryTimeRenewalTest.class);
private static final String HOST_PROPERTY = RegistryClient.class.getName() + ".host";
public static final String CARTA_IMAGE_SUFFIX = "/skaha/carta:3.0";
public static final String PROD_IMAGE_HOST = "images.canfar.net";
public static final String DEV_IMAGE_HOST = "images-rc.canfar.net";
public static final int SLEEP_TIME_SECONDS = 5;
private static final Logger log = Logger.getLogger(ExpiryTimeRenewalTest.class);

static {
Log4jInit.setLevel("org.opencadc.skaha", Level.INFO);
}

protected final URL sessionURL;
protected final Subject userSubject;
protected final String imageHost;

public ExpiryTimeRenewalTest() throws Exception {
// determine image host
String hostP = System.getProperty(HOST_PROPERTY);
if (hostP == null || hostP.trim().isEmpty()) {
throw new IllegalArgumentException("missing server host, check " + HOST_PROPERTY);
} else {
hostP = hostP.trim();
if (hostP.startsWith("rc-")) {
imageHost = DEV_IMAGE_HOST;
} else {
imageHost = PROD_IMAGE_HOST;
}
}

RegistryClient regClient = new RegistryClient();
final URL sessionServiceURL = regClient.getServiceURL(SessionUtil.getSkahaServiceID(), Standards.PROC_SESSIONS_10, AuthMethod.TOKEN);
this.sessionURL = new URL(sessionServiceURL.toString() + "/session");
Expand All @@ -140,11 +120,12 @@ public ExpiryTimeRenewalTest() throws Exception {
public void testRenewCARTA() throws Exception {
Subject.doAs(userSubject, (PrivilegedExceptionAction<Void>) () -> {
// ensure that there is no active session
initialize();
SessionUtil.initializeCleanup(this.sessionURL);

// create carta session
final String cartaSessionID = SessionUtil.createSession(this.sessionURL, "inttest-" + SessionAction.SESSION_TYPE_CARTA,
imageHost + CARTA_IMAGE_SUFFIX);
SessionUtil.getImageByName(ExpiryTimeRenewalTest.CARTA_IMAGE_SUFFIX).getId(),
SessionAction.SESSION_TYPE_CARTA);
Session cartaSession = SessionUtil.waitForSession(this.sessionURL, cartaSessionID, Session.STATUS_RUNNING);

// Sleep to force time to pass before renewal
Expand Down Expand Up @@ -181,11 +162,11 @@ public void testRenewHeadless() throws Exception {
Subject.doAs(userSubject, (PrivilegedExceptionAction<Void>) () -> {

// ensure that there is no active session
initialize();
SessionUtil.initializeCleanup(this.sessionURL);

// create headless session
final String headlessSessionID = SessionUtil.createHeadlessSession(
SessionUtil.getDesktopAppImageOfType("/skaha/terminal").getId(), this.sessionURL);
SessionUtil.getDesktopAppImageOfType("/skaha/terminal").getId(), this.sessionURL);
Session headlessSession = SessionUtil.waitForSession(this.sessionURL, headlessSessionID, Session.STATUS_RUNNING);
final Instant headlessExpiryTime = Instant.parse(headlessSession.getExpiryTime());

Expand All @@ -210,11 +191,12 @@ public void testRenewHeadless() throws Exception {
public void testRenewDesktop() throws Exception {
Subject.doAs(userSubject, (PrivilegedExceptionAction<Object>) () -> {
// ensure that there is no active session
initialize();
SessionUtil.initializeCleanup(this.sessionURL);

// create desktop session
final String desktopSessionID = SessionUtil.createSession(this.sessionURL, "inttest-" + SessionAction.SESSION_TYPE_DESKTOP,
SessionUtil.getImageOfType(SessionAction.SESSION_TYPE_DESKTOP).getId());
SessionUtil.getImageOfType(SessionAction.SESSION_TYPE_DESKTOP).getId(),
SessionAction.SESSION_TYPE_DESKTOP);
SessionUtil.waitForSession(this.sessionURL, desktopSessionID, Session.STATUS_RUNNING);

// create desktop app
Expand Down Expand Up @@ -246,39 +228,10 @@ public void testRenewDesktop() throws Exception {
});
}

private void initialize() throws Exception {
List<Session> sessions = getSessions();
for (Session session : sessions) {
// skip dekstop-app, deletion of desktop-app is not supported
if (!session.getType().equals(SessionAction.TYPE_DESKTOP_APP)) {
deleteSession(sessionURL, session.getId());
}
}

int count = 0;
sessions = getSessions();
for (Session s : sessions) {
if (!s.getType().equals(SessionAction.TYPE_DESKTOP_APP)) {
count++;
}
}
Assert.assertEquals("zero sessions #1", 0, count);
}

private void deleteSession(URL sessionURL, String sessionID) throws MalformedURLException {
HttpDelete delete = new HttpDelete(new URL(sessionURL.toString() + "/" + sessionID), true);
delete.run();
Assert.assertNull("delete session error", delete.getThrowable());
}

private void renewSession(URL sessionURL, String sessionID) throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("action", "renew");
HttpPost post = new HttpPost(new URL(sessionURL.toString() + "/" + sessionID), params, false);
post.prepare();
}

private List<Session> getSessions() throws Exception {
return SessionUtil.getSessions(this.sessionURL, Session.STATUS_TERMINATING);
}
}
Loading

0 comments on commit 1352f6a

Please sign in to comment.